JQuery Cycle 插件向右随机播放

发布于 2024-12-26 00:02:15 字数 4306 浏览 1 评论 0原文

固定的!不敢相信我之前没有看到这一点:

$('#s4') 
        .before('<div id="nav">') 
        .cycle({ 
            fx:     'shuffle', 
            speed:  500, 
            shuffle: { top:15, left: 300 },
            timeout: 0, 
            pager:  '#nav',
            cleartypeNoBg:true
    });

您可以在此处选择随机播放动画。我将我的设置为 top:15 和 left:300


我正在尝试使用 Cycle 插件,但我需要它向右而不是向左洗牌。我已经通过更改为成功完成了此操作。

opts.shuffle = opts.shuffle || {left:-w, top:15};

唯一

opts.shuffle = opts.shuffle || {left:+w, top:15};

的问题是我正在洗牌的图像非常大,并且在图像之间的转换过程中创建了水平滚动条。当它向左移动并且我不确定我错过了什么时,这种情况不会发生。下面是随机播放效果的片段。任何帮助表示赞赏!

// shuffle
$.fn.cycle.transitions.shuffle = function($cont, $slides, opts) {
    var i, w = $cont.css('overflow', 'visible').width();
    $slides.css({left: 0, top: 0});
    opts.before.push(function(curr,next,opts) {
        $.fn.cycle.commonReset(curr,next,opts,true,true,true);
    });
    // only adjust speed once!
    if (!opts.speedAdjusted) {
        opts.speed = opts.speed / 2; // shuffle has 2 transitions
        opts.speedAdjusted = true;
    }
    opts.random = 0;
    opts.shuffle = opts.shuffle || {left:+w, top:15};
    opts.els = [];
    for (i=0; i < $slides.length; i++)
        opts.els.push($slides[i]);

    for (i=0; i < opts.currSlide; i++)
        opts.els.push(opts.els.shift());

    // custom transition fn (hat tip to Benjamin Sterling for this bit of sweetness!)
    opts.fxFn = function(curr, next, opts, cb, fwd) {
        var $el = fwd ? $(curr) : $(next);
        $(next).css(opts.cssBefore);
        var count = opts.slideCount;
        $el.animate(opts.shuffle, opts.speedIn, opts.easeIn, function() {
            var hops = $.fn.cycle.hopsFromLast(opts, fwd);
            for (var k=0; k < hops; k++)
                fwd ? opts.els.push(opts.els.shift()) : opts.els.unshift(opts.els.pop());
            if (fwd) {
                for (var i=0, len=opts.els.length; i < len; i++)
                    $(opts.els[i]).css('z-index', len-i+count);
            }
            else {
                var z = $(curr).css('z-index');
                $el.css('z-index', parseInt(z)+1+count);
            }
            $el.animate({left:0, top:0}, opts.speedOut, opts.easeOut, function() {
                $(fwd ? this : curr).hide();
                if (cb) cb();
            });
        });
    };
    opts.cssBefore = { display: 'block', opacity: 1, top: 0, left: 0 };
};

超文本标记语言

<div id="contentAreaJS" class="contentArea">
    <div id="s4" class="pics">
        <div id="navlist">
        <ul>
            <li id="mon"><a href="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/ChilisLightbox_fajitas.png" style="text-decoration:none;" rel="shadowbox;width=500;height=400;"></a></li>
            <li id="tue"><a href="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/ChilisLightbox_tacos.png" style="text-decoration:none;" rel="shadowbox;width=500;height=400;"></a></li>
            <li id="wed"><a href="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/ChilisLightbox_chips.png" style="text-decoration:none;" rel="shadowbox;width=500;height=400;"></a></li>
            <li id="thur"><a href="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/ChilisLightbox_dessert.png" style="text-decoration:none;" rel="shadowbox;width=500;height=400;"></a></li>
            <li id="fri"><a href="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/ChilisLightbox_burger.png" style="text-decoration:none;" rel="shadowbox;width=500;height=400;"></a></li>
        </ul>
    </div>
        <a href="https://www.chilistogo.com/Pages/Welcome.aspx" target="_blank"><img src="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/ChilispartyPlatters.png" height="237" width="769" /></a>
    <a href="http://www.chilis.com/EN/HappyHours/001.005.0609.pdf" target="_blank"><img src="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/ChilishappyHour.png" height="237" width="769" /></a>
        </div>     
    </div>

Fixed! Can't believe I didn't see this before:

$('#s4') 
        .before('<div id="nav">') 
        .cycle({ 
            fx:     'shuffle', 
            speed:  500, 
            shuffle: { top:15, left: 300 },
            timeout: 0, 
            pager:  '#nav',
            cleartypeNoBg:true
    });

You can select the shuffle animation here. I have mine set to top:15 and left:300


I'm trying to use the Cycle Plugin but I need it to shuffle to the right instead of the left. I've done this successfully by changing

opts.shuffle = opts.shuffle || {left:-w, top:15};

to

opts.shuffle = opts.shuffle || {left:+w, top:15};

The only problem is that the image I'm shuffling is quiet large and is creating a horizontal scroll bar during the transition between images. This doesn't happen when it's shuffling left and I'm not sure what I'm missing. Below is the snippet for the shuffle effect. Any help is appreciated!

// shuffle
$.fn.cycle.transitions.shuffle = function($cont, $slides, opts) {
    var i, w = $cont.css('overflow', 'visible').width();
    $slides.css({left: 0, top: 0});
    opts.before.push(function(curr,next,opts) {
        $.fn.cycle.commonReset(curr,next,opts,true,true,true);
    });
    // only adjust speed once!
    if (!opts.speedAdjusted) {
        opts.speed = opts.speed / 2; // shuffle has 2 transitions
        opts.speedAdjusted = true;
    }
    opts.random = 0;
    opts.shuffle = opts.shuffle || {left:+w, top:15};
    opts.els = [];
    for (i=0; i < $slides.length; i++)
        opts.els.push($slides[i]);

    for (i=0; i < opts.currSlide; i++)
        opts.els.push(opts.els.shift());

    // custom transition fn (hat tip to Benjamin Sterling for this bit of sweetness!)
    opts.fxFn = function(curr, next, opts, cb, fwd) {
        var $el = fwd ? $(curr) : $(next);
        $(next).css(opts.cssBefore);
        var count = opts.slideCount;
        $el.animate(opts.shuffle, opts.speedIn, opts.easeIn, function() {
            var hops = $.fn.cycle.hopsFromLast(opts, fwd);
            for (var k=0; k < hops; k++)
                fwd ? opts.els.push(opts.els.shift()) : opts.els.unshift(opts.els.pop());
            if (fwd) {
                for (var i=0, len=opts.els.length; i < len; i++)
                    $(opts.els[i]).css('z-index', len-i+count);
            }
            else {
                var z = $(curr).css('z-index');
                $el.css('z-index', parseInt(z)+1+count);
            }
            $el.animate({left:0, top:0}, opts.speedOut, opts.easeOut, function() {
                $(fwd ? this : curr).hide();
                if (cb) cb();
            });
        });
    };
    opts.cssBefore = { display: 'block', opacity: 1, top: 0, left: 0 };
};

HTML

<div id="contentAreaJS" class="contentArea">
    <div id="s4" class="pics">
        <div id="navlist">
        <ul>
            <li id="mon"><a href="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/ChilisLightbox_fajitas.png" style="text-decoration:none;" rel="shadowbox;width=500;height=400;"></a></li>
            <li id="tue"><a href="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/ChilisLightbox_tacos.png" style="text-decoration:none;" rel="shadowbox;width=500;height=400;"></a></li>
            <li id="wed"><a href="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/ChilisLightbox_chips.png" style="text-decoration:none;" rel="shadowbox;width=500;height=400;"></a></li>
            <li id="thur"><a href="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/ChilisLightbox_dessert.png" style="text-decoration:none;" rel="shadowbox;width=500;height=400;"></a></li>
            <li id="fri"><a href="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/ChilisLightbox_burger.png" style="text-decoration:none;" rel="shadowbox;width=500;height=400;"></a></li>
        </ul>
    </div>
        <a href="https://www.chilistogo.com/Pages/Welcome.aspx" target="_blank"><img src="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/ChilispartyPlatters.png" height="237" width="769" /></a>
    <a href="http://www.chilis.com/EN/HappyHours/001.005.0609.pdf" target="_blank"><img src="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/ChilishappyHour.png" height="237" width="769" /></a>
        </div>     
    </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不如归去 2025-01-02 00:02:15

您没有发布任何 html,而是将 overflow:hidden 添加到溢出的容器的 css 中(获取滚动条)。您可能需要使用 before/after 挂钩来控制这一点,以便页面布局在转换完成后恢复正常。

You didn't post any html, but add overflow: hidden to the css of the container that is overflowing (getting the scrollbar). You may need to use the before/after hooks to control this so that page layout returns to normal after the transition completes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文