javascript - fancyBox3 - 如何在单击打开的图像时禁用缩放

标签 javascript jquery fancybox fancybox-3

美好的一天。

我遇到这样的问题:当打开 fancyBox 画廊并且我只需单击打开的图像(幻灯片)时,图像正在缩放。我需要禁用这种行为。

文档中建议使用 clickContent 事件来自定义行为。我从文档中获取示例,并通过以下方式初始化我的图库副本:

$("[data-fancybox]").fancybox({
    clickContent : function( current, event ) {
        // return current.type === 'image' ? 'zoom' : false;
        if (current.type === 'image') {
            return false;
        }
    },
    slideShow: false,
    fullScreen: false,
    thumbs: false
});

但是 clickContent 覆盖不起作用。我尝试过 console.log() clickContent 事件:

$("[data-fancybox]").fancybox({
    clickContent : function( current, event ) {
        // return current.type === 'image' ? 'zoom' : false;
        console.log('clicking test!');
    },
    slideShow: false,
    fullScreen: false,
    thumbs: false
});

但是我没有成功。

也许我在某个地方犯了错误。请纠正我。预先感谢您!

最佳答案

更新到 v3.1 并使用 clickContent 选项来选择用户单击内容时的操作。可能的值:

"close"           - close instance
"next"            - move to next gallery item
"nextOrClose"     - move to next gallery item or close if gallery has only one item
"toggleControls"  - show/hide controls
"zoom"            - zoom image (if loaded successfully)
false             - do nothing

它也可以是从列表中返回值的函数。默认值:

clickContent : function( current, event ) {
  return current.type === 'image' ? 'zoom' : false;
}

此外,您的代码片段工作正常 - https://codepen.io/anon/pen/GvNdJE

关于javascript - fancyBox3 - 如何在单击打开的图像时禁用缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45503720/

相关文章:

fancybox - 向 fancybox2 添加不带填充的边框半径

javascript - Fancybox 在框中加载整个页面而不是文本 div

javascript - IE6 : JavaScript hyperlink not working

jquery - 添加图像作为 jquery 数据表中的行值

javascript - 在 Node.js 中,从同一文件中的另一个函数引用一个函数会导致 'ReferenceError: -function- is not defined' 错误

javascript - 如何使用 html、css 和 js 添加自定义动画弹出按钮?

javascript - 如果动态添加 "!important",则获取元素的实际 CSS 属性

javascript - 使用 Cookie 禁用 Fancybox 弹出窗口

javascript - 我对 For 循环的理解正确吗?我缺少什么? - JavaScript

javascript - 如何在页面上添加数百个形状而不减慢页面加载速度