【问题标题】:Magnific-popup closed when I click on arrows (right/left)当我点击箭头时关闭放大弹出窗口(右/左)
【发布时间】:2015-04-30 06:46:46
【问题描述】:

我正在为画廊使用magnific-popup 插件,并且我使用fonts-awesome 字体中的箭头更改了默认箭头样式,但是在打开画廊并开始单击右/左箭头后,在特定区域中弹出窗口关闭。 . 这里jsfiddle演示

$('.related-gallery').magnificPopup({
            type: 'image',
            gallery:{
                enabled:true,
                arrowMarkup: '<button title="%title%" type="button" class="mfp-arrow custom-mfp-arrow-%dir%"><i class="fa fa-angle-%dir% fa-4x"></i></button>'
            },
            zoom: {
                enabled: true, // By default it's false, so don't forget to enable it

                duration: 300, // duration of the effect, in milliseconds
                easing: 'ease-in-out', // CSS transition easing function 

                // The "opener" function should return the element from which popup will be zoomed in
                // and to which popup will be scaled down
                // By defailt it looks for an image tag:
                opener: function(openerElement) {
                  // openerElement is the element on which popup was initialized, in this case its <a> tag
                  // you don't need to add "opener" option if this code matches your needs, it's defailt one.
                  return openerElement.is('img') ? openerElement : openerElement.find('img');
                }
            }
        });

【问题讨论】:

    标签: jquery css magnific-popup


    【解决方案1】:

    我可以通过将 mfp-prevent-close 类添加到我的 FontAwesome 图标来解决此问题。

    因此,您在图库中的 arrowMarkup 设置将是:

    arrowMarkup: '&lt;button title="%title%" type="button" class="mfp-arrow custom-mfp-arrow-%dir%"&gt;&lt;i class="fa fa-angle-%dir% fa-4x mfp-prevent-close"&gt;&lt;/i&gt;&lt;/button&gt;'

    如果没有该类,它会将自定义箭头的点击读取为背景点击 - 这就是 DigitalDouble 禁用背景点击以关闭图库的解决方案有效的原因。您会注意到,即使画廊正在关闭,它也会短暂显示下一张图片。所以导航仍然正常工作,它只是有关闭画廊的额外动作:)

    【讨论】:

    • 这对我有用,谢谢 - 也使用 FontAwesome 左右箭头:-)
    • 正确的类是 mfp-prevent-close 作为你的例子,而不是你的首要描述:)
    • 很好,谢谢!我已经编辑了我的答案,以便类在两个地方都是正确的。
    • 在 Font Awesome 5 中对我不起作用。将 css pointer-events: none 添加到 .mfp-arrow svg 以防止内部 svg 元素注册点击。无论如何,按钮元素都会处理。
    • 使用 SVG 和折线而不是 Font Awesome,它与添加到折线元素的 mfp-prevent-close 一起使用
    【解决方案2】:

    尝试在配置中添加这个:

    closeOnBgClick: false

    【讨论】:

    • 它可以工作,但在点击图像外的任何地方时关闭关闭..但这不是大问题!谢谢
    • 顺便说一句,你知道,你的小提琴在我这边工作得很好。单击箭头不会关闭弹出窗口。在某些情况下,您会不小心单击 bg 从而关闭弹出窗口。
    • 是的,一开始我以为是这样,但是在我给箭头持有者(按钮)添加背景颜色后,点击按钮它自己没有退出,问题仍然存在jsfiddle.net/fayekramzy/ddarryom/1,当我点击图标周围的一些位置时引起的问题..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    相关资源
    最近更新 更多