我有一个WordPress gallery 网站,在那里图像在Bootstrap 5模式中打开,这打开了Bootstrap Carousel.
图像被加载到带有php Foreach循环的POST循环中,每个幻灯片一个.
我正在try 添加悬停放大到每个图像与一个小圆圈使用blowup.js.
我有每个幻灯片正确移动的zoom 功能,但是只有第一个图像跟踪鼠标所在的位置.随后的放大显示在左上角.
Here is my Function:个
(function ($) {
// Update blowup when slide changes
$("#gallery-carousel").on('slide.bs.carousel', function (){
$(".img-zoom").blowup("destroy");
});
$("#gallery-carousel").on('slid.bs.carousel', function (){
$(".img-zoom").blowup()
});
})(jQuery);
This is the code that the function targets within the Carousel:个
<div class="carousel-item">
<div class="position-relative carousel-img">
<img class="img-fluid img-zoom" src="<?php echo $image_url; ?>" />
</div>
</div>
This is the JQuery in the plugin that is meant to track the zoomed coordinates:个
// Mouse motion on image
$element.mousemove(function (e) {
// Lens position coordinates
var lensX = e.pageX - $options.width / 2;
var lensY = e.pageY - $options.height / 2;
// Relative coordinates of image
var relX = e.pageX - $(this).offset().left;
var relY = e.pageY - $(this).offset().top;
// Zoomed image coordinates
var zoomX = -Math.floor(relX / $element.width() * (NATIVE_IMG.width * $options.scale) - $options.width / 2);
var zoomY = -Math.floor(relY / $element.height() * (NATIVE_IMG.height * $options.scale) - $options.height / 2);
var backPos = zoomX + "px " + zoomY + "px";
var backgroundSize = NATIVE_IMG.width * $options.scale + "px " + NATIVE_IMG.height * $options.scale + "px";
})