Files
nexusphp/public/js/nexus.js
T

40 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-08-10 17:38:05 +08:00
jQuery(document).ready(function () {
jQuery('.spoiler-title').on('click', function () {
let content = jQuery(this).parent().next();
if (content.hasClass('collapse')) {
content.height(content[0].scrollHeight).removeClass('collapse')
} else {
content.height(0).addClass('collapse')
}
})
2022-08-23 02:25:51 +08:00
function getPosition(e, imgEle) {
let imgWidth = imgEle.prop('naturalWidth')
let imgHeight = imgEle.prop("naturalHeight")
let left = e.pageX + 10;
if (left + imgWidth > window.innerWidth) {
left = e.pageX - 10 - imgWidth
}
let top = e.pageY + 10;
if (top + imgHeight > window.innerHeight) {
top = e.pageY - imgHeight / 2
}
return {left, top}
}
2022-08-10 17:38:05 +08:00
var previewEle = jQuery('#nexus-preview')
2022-08-23 02:25:51 +08:00
var imgEle
2022-08-21 15:22:08 +08:00
jQuery(".preview").hover(function (e) {
2022-08-23 02:25:51 +08:00
imgEle = jQuery(this);
let position = getPosition(e, imgEle)
let src = imgEle.attr("src")
2022-08-10 17:38:05 +08:00
if (src) {
2022-08-23 02:25:51 +08:00
previewEle.attr("src", src).css(position).fadeIn("fast");
2022-08-10 17:38:05 +08:00
}
2022-08-21 15:22:08 +08:00
}, function (e) {
previewEle.fadeOut("fast");
}).on("mousemove", function (e) {
2022-08-23 02:25:51 +08:00
let position = getPosition(e, imgEle)
previewEle.css(position)
2022-08-21 15:22:08 +08:00
})
2022-08-10 17:38:05 +08:00
})