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 (将#修改为@)