gpt4 book ai didi

javascript - 将点击事件绑定(bind)到 jqzoom 以启动 fancybox

转载 作者:行者123 更新时间:2023-12-02 18:19:27 25 4
gpt4 key购买 nike

所以我已经研究了一段时间,但无法从 jqzoomed 元素触发绑定(bind)的点击事件。

HTML:

<div class="product-clicktozoom-image">
<div class="product-clicktozoom-image-main">
<a href="http://example.com/image.jpg" class="jqzoom" title="Image" rel="gall"><img itemprop="image" id="mainimage" src="http://exampe.com/image.jpg" alt="Image" title="Image"/></a>
</div>
</div>

JS:

jQuery(document).load(function() {
jQuery('#mainimage').bind('click',function(){
var fancyImage = jQuery('#mainimage').attr('src');
jQuery.fancybox.open(fancyImage);
});
});

jqzoom 创建了几个额外的 div,因此最终的页面结构实际上如下所示:

<div class="product-clicktozoom-image-main">
<a href="example.com/image.jpg" class="jqzoom" title="" rel="gall" style="outline-style: none; text-decoration: none;">
<div class="zoomPad">
<img itemprop="image" id="mainimage" src="http://example.com/image.jpg" alt="Image" title="Image" style="opacity: 1;">
<div class="zoomPup" style="display: none; top: 105px; left: 145px; width: 126px; height: 126px; position: absolute; border-width: 1px;"></div>
<div class="zoomWindow" style="position: absolute; z-index: 5001; cursor: default; left: 0px; top: 0px; display: none;">
<div class="zoomWrapper" style="border-width: 1px; width: 355px; cursor: crosshair;">
<div class="zoomWrapperTitle" style="width: 100%; position: absolute; display: none;"></div>
<div class="zoomWrapperImage" style="width: 100%; height: 355px;">
<img src="http://example.com/image.jpg" style="position: absolute; border: 0px; display: block; left: -411.26760563380276px; top: -298.5915492957746px;">
</div>
</div>
</div>
<div class="zoomPreload" style="visibility: hidden; top: 156px; left: 132.5px; position: absolute;">Loading zoom</div>
</div>
</a>
</div>

我尝试将单击事件绑定(bind)到#mainimage,以及zoomPad类以及zoomWrapperImage元素中的img,因为当您将鼠标悬停在图像上时,这似乎是顶部元素。

我想要做的就是如果他们单击缩放(当前缩放发生在鼠标悬停时),则在 fancybox 中打开完整图像。我知道 fancybox.open(fancyImage);有效,我可以直接在控制台中成功运行单击函数中的代码,我只是无法从单击事件本身触发它。

救命!

最佳答案

最终结果非常简单,点击事件需要绑定(bind)在 .zoomPad 上,我使用 window.load 代替 (document).ready,因为这样可以确保所有元素都已加载。

最终 JS:

jQuery(window).load(function() {
jQuery('.zoomPad').bind('click',function(){
var fancyImage = jQuery('.zoomWrapperImage img').attr('src');
jQuery.fancybox.open([{href : fancyImage}], {closeClick : true});
});
});

关于javascript - 将点击事件绑定(bind)到 jqzoom 以启动 fancybox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18963635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com