将点击事件绑定到 jqzoom 以启动 Fancybox
binding a click event to jqzoom to launch fancybox
所以我已经玩了一段时间了,但无法让绑定的点击事件从 jqzoomed 元素触发。
.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>
我尝试将单击事件与 zoomPad 类以及 zoomWrapperImage 元素中的 img 绑定到 #mainimage,因为当您将鼠标悬停在图像上时,这似乎是顶部元素。
我要做的就是在他们单击缩放时在花哨的框中打开完整图像(目前缩放发生在鼠标悬停时)。我知道fancybox.open(fancyImage);工作,我可以直接在控制台中成功运行点击函数中的代码,我只是无法让它从点击事件本身触发。
帮助!
最终证明
这非常简单,单击事件需要在 .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});
});
});
相关文章:
- 我的jQuery插件参数没有正确启动,遇到了问题
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 从控制器返回后Ajax启动事件激发
- Meteor上的启动页面
- 如何防止网页加载后自动启动功能
- 如何从JavaScriptInterface启动Navigation Drawer
- window.on.scroll事件未启动
- 单击按钮后启动javascript提示
- 在javaservlet doPost方法中启动线程时,无法返回异常消息
- spine.js在启动时填充模型实例
- 如何在所有ng点击事件AngularJS上启动一个方法
- jQuery悬停在没有鼠标悬停的情况下启动
- SignalR客户端启动连接时如何设置用户
- Meteor:在启动时将html注入客户端文件
- Angular UI启动日期选择器问题
- 如何用低音量自动启动Youtube视频(iframe)
- jQuery mouseup在拖离链接后未启动
- 在同一选项卡中启动下载,而无需在Javascript中打开新选项卡或窗口
- 为什么我的控制器没有启动函数.js脚本
- 将点击事件绑定到 jqzoom 以启动 Fancybox