mirror of
https://github.com/LalleSX/4chan-XZ.git
synced 2026-01-30 09:48:12 +01:00
fix image going off screen
This commit is contained in:
parent
2fe2cb2c5c
commit
92db1462be
@ -14,21 +14,23 @@ export function initImageHovering(): void {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Find all thumbnail images on the page
|
// Find all thumbnail images on the page
|
||||||
const thumbnails = $("a.fileThumb")
|
const thumbnails = $("a.fileThumb") as JQuery<HTMLAnchorElement>
|
||||||
|
|
||||||
// Attach hover events to each thumbnail image
|
// Attach hover events to each thumbnail image
|
||||||
thumbnails.each(function () {
|
thumbnails.each(function () {
|
||||||
const thumbnail = $(this)
|
const thumbnail = $(this)
|
||||||
const imageUrl = thumbnail.attr("href") as string
|
const imageUrl = thumbnail.attr("href") as string
|
||||||
|
|
||||||
// Create a new image element to be displayed on hover
|
// Create a new image element to be displayed on hover
|
||||||
const hoverImage = $("<img>")
|
const hoverImage = $("<img>")
|
||||||
.attr("src", imageUrl)
|
.attr("src", imageUrl)
|
||||||
.css({
|
.css({
|
||||||
position: "absolute",
|
position: "fixed",
|
||||||
display: "none",
|
display: "none",
|
||||||
border: "1px solid #000",
|
border: "none",
|
||||||
|
maxWidth: "100%",
|
||||||
|
maxHeight: "100%",
|
||||||
})
|
})
|
||||||
.appendTo("body")
|
.appendTo("body")
|
||||||
|
|
||||||
@ -43,9 +45,21 @@ export function initImageHovering(): void {
|
|||||||
|
|
||||||
// Update the hover image position based on the mouse cursor
|
// Update the hover image position based on the mouse cursor
|
||||||
thumbnail.on("mousemove", (event) => {
|
thumbnail.on("mousemove", (event) => {
|
||||||
|
const offsetX = 10
|
||||||
|
const offsetY = 10
|
||||||
|
|
||||||
|
const imageWidth = hoverImage.width() as number
|
||||||
|
const imageHeight = hoverImage.height() as number
|
||||||
|
|
||||||
|
const windowWidth = $(window).width() as number
|
||||||
|
const windowHeight = $(window).height() as number
|
||||||
|
|
||||||
|
const left = Math.min(event.pageX + offsetX, windowWidth - imageWidth - offsetX)
|
||||||
|
const top = Math.min(event.pageY + offsetY, windowHeight - imageHeight - offsetY)
|
||||||
|
|
||||||
hoverImage.css({
|
hoverImage.css({
|
||||||
left: event.pageX + 10 + "px",
|
left: left + "px",
|
||||||
top: event.pageY + 10 + "px",
|
top: top + "px",
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user