如何解决Fancybox 3-使用触发器在Fancybox中打开图像,但不单击图像
我正在尝试找到一种方法,仅在单击触发器(通过属性data-fancybox-href
)时使用Fancybox 3打开图像。单击源图像本身时,它不应打开fancybox,而应打开其他页面(默认属性href
)。但是,Fancybox必须使用源图像,因为只有这样animationEffect: "zoom"
才会发生。
这似乎出乎意料地困难,我在Fancybox 3中没有找到解决该问题的集成方法。我将不胜感激。
这是一个基本示例和JSFiddle。在这种情况下,btn会在图像上触发click
事件,从而打开Fancybox,或者图像本身打开Fancybox。我只希望第一个发生,而不要在图像上发生。
<div class="product">
<div class="media">
<a href="https://www.google.com/" class="product-image-link" data-fancybox="shop-gallery" data-fancybox-href="https://cdn.pixabay.com/photo/2015/12/01/20/28/road-1072823__340.jpg">
<img width="280" height="200" src="https://cdn.pixabay.com/photo/2015/12/01/20/28/road-1072823__340.jpg">
</a>
</div>
<span class="product-lightbox-btn">Expand</span>
</div>
<script>
$( "[data-fancybox]" ).fancybox(
{
animationEffect: "zoom",beforeLoad : function(instance,current) {
// Alternative img link
var dataFancyboxHref = current.opts.$orig.attr( "data-fancybox-href" );
this.src = dataFancyboxHref;
},}
);
$( ".product-lightbox-btn" ).click( function() {
$(this).closest( '.product' ).find( '.product-image-link' ).trigger( 'click' );
});
</script>
https://jsfiddle.net/v1n3e2zy/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。