简体   繁体   English

第二次使用boxslider打开fancybox无法正常工作

[英]Opening fancybox with boxslider for second time doesn't work properly

So I've setup a fancybox with boxslider. 所以我用boxslider设置了一个化装箱。 I have some problems with the boxslider when opening the fancybox again after closing it the first time. 第一次关闭后,再次打开fancybox时,boxslider出现了一些问题。

website (please note that the onclick is only applied to the first block (top row, most left)) 网站 (请注意,onclick仅适用于第一个区块(顶部行,最左侧))

The fancybox is called by the code below: fancybox由以下代码调用:

<div class="img-spacer" onclick="$.fancybox({href : '#portfolio-1', width: 1040, margin: 0, padding: 0, closeBtn: false}); $('.bxslider').bxSlider({auto: true,controls: false,pager: false});">

This code works just fine when opening the fancybox for the first time but when I close the fancybox and open it again the boxslider is not working anymore like it is supposed to. 第一次打开fancybox时,此代码工作得很好,但是当我关闭fancybox并再次打开它时,boxslider不再正常工作。 It will skip some photo's and won't slide smoothly. 它将跳过一些照片,并且不会平滑滑动。

Any suggestions on how to fix this? 对于如何解决这个问题,有任何的建议吗?

Like I mentioned in my comment, you need to move the fancybox init out of the inline click handler, in into your JS file. 就像我在评论中提到的那样,您需要将fancybox初始化移出内联单击处理程序,移入JS文件中。

$(document).ready(function() {
    // Attach fancybox to every .image-spacer div
    $("img-spacer").fancybox({
        href : '#portfolio-1', 
        width: 1040, 
        margin: 0,
        padding: 0,
        closeBtn: false,
        onUpdate: function() {
            alert('update!');
        },
        onCancel: function() {
            alert('cancel!');
        },
        onPlayStart: function() {
            alert('play start!');
        },
        onPlayEnd: function() {
            alert('play end!');
        },
        beforeClose: function() {
            alert('before close!');
        },
        afterClose: function() {
            alert('after close!');
        },
        beforeShow: function() {
            alert('before show!');
        },
        afterShow: function() {
            alert('after show!');
        },
        beforeLoad: function() {
            alert('before load!');
        },
        afterLoad: function() {
            alert('after load!');
        }
    });

    // On clicking a .img-spacer div, attach a bxSlider
    $(".portfolio").click(function(){
        $('.bxslider').bxSlider({
            auto: true,
            controls: false,
            pager: false
        });
    });
});

And for the HTML 对于HTML

<div class="img-spacer"></div>

Give this a shot and let me know how it went. 试一试,让我知道如何进行。 If you place it on the live site I can take a look at it there. 如果您将其放在实时网站上,我可以在那里查看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM