Jquery Cycle —multiple nested slideshows and cycle terminating

心已入冬 提交于 2019-12-03 20:23:29

A facebook friend solved it! Thanks, facebook friend!

var slideshow = $('#home-slides').cycle({
    fx: 'scrollHorz',
    speed: 300,
    timeout: 0,
    before: function(curElement, nextElement, options, forwardFlag) {
        if($(nextElement).children('.slide-up').length != 0) {
            $(nextElement).children('.slide-up').cycle({
                fx: 'scrollUp',
                timeout: 2000,
                autostop: true,
                end: function() { slideshow.cycle('next'); }
            });
        }
        else {
            setTimeout(function(){ slideshow.cycle('next'); }, 2000);
        }
    }
});

Working example here: http://dl.dropbox.com/u/2890872/js-test/index3.html I need to study Cycle a bit more and the changes he's made to fully understand the role of 'nextElement' in this code, but it most certainly works!

Zero

Check if this approach helps you: http://www.devcha.com/2010/05/fixed-cycle-terminating-too-few-slides.html

Did you check this question...looks similar problem, but different approach: Nested jQuery Cycle?

ddlab

After I "awarded" the cycle plugin as the best and simpliest slideshow plugin ever, I put some eyes more on it, and did some experiments and spent some hours with it. Results: 1. the cycle().cycle('stop') as same as just cycle('stop') never worked properly, it stops the inner slideshows after every 2nd content. I changed it into a single cycle({timeout:0})... which I do not really understand, but it works absolutely fine, including firebug reviews on js activity. 2. As I needed it to be working on more than just one usage per page, and the aibility to auto-decision, if controls are needed or not, so I changed a couple of things and put the entire js in the $(document).ready(function() {} in the header of the page. The first .inner-slideshow gets an added class="active" from serverside php script.

The code now looks like that

//-----------------jquery cycle plugin modified by Michael Gerner, ddlab, 2012-01-15---------------
$('.slideshow').each(function(){

    var sl = $(this);
    var sl_index = sl.index('.slideshow');
    var allinner = sl.find('.inner-slideshow');
    var firstinner = sl.children('.inner-slideshow:eq(0)');

    //----settings outer slideshow
    var outerfx = 'scrollHorz';
    var outerspeed = 500;
    var outertimeout = 0;
    var outerprev = '#sl'+sl_index+'prev';
    var outernext = '#sl'+sl_index+'next';

    //----settings inner slideshow
    var innerfx = 'fade';
    var innerspeed = 2000;
    var innertimeout = 6000;

    if (allinner.size() > 1) { //---------more than one inner slideshow
        var setcontrols = '<div class="slideshow-controls"><a class="prev" id="sl'+sl_index+'prev" href="#"></a> <a class="next" id="sl'+sl_index+'next" href="#"></a></div>';
        sl.after(setcontrols);
        var controls_a = sl.find('.slideshow-controls a');

        controls_a.click(function(){
            var activeinners = sl.find('.active');
            activeinners.each(function(){
                $(this).removeClass('active').cycle({timeout:0});
            });
        });

        sl.cycle({
            fx:outerfx,
            speed:outerspeed,
            timeout:outertimeout,
            prev:outerprev,
            next:outernext,
            before:function(){
                var activeinners = sl.find('.active');
                activeinners.each(function(){
                    $(this).removeClass('active').cycle({timeout:0});
                });
            },
            after:function(){
                $(this).addClass('active').cycle({
                    fx:innerfx,
                    speed:innerspeed,
                    timeout:innertimeout,
                    autostop: true,
                    end: function() { sl.cycle('next'); }
                });
            }
        });
    }
    else { //------------just one inner slideshow
        firstinner.cycle({
            fx:innerfx,
            speed:innerspeed,
            timeout:innertimeout
        });
    }
});
//-----------------jquery cycle plugin modified by Michael Gerner, ddlab, 2012-01-15---------------

Now I am happy with it, specially the browserload on js activity is extremely small, which I want to point out as important for mobile devices, and finally I added some frontend-editing tools, such as html5upload and a jq-filemanager, which is used for the owner of the website to manage the content for the gallery.

Thanks for all previous reviews and tuts, that helped me a lot to get this track :-) You may find a lightweight screenshot image (26kb) on here http://ddlab.de/screenshots/cycle_gallery.jpg

I uploaded the working example here http://ferienhaus-fischland-ahrenshoop.de/mini4/ After finishing this project in the near future, you´ll find the gallery anywhere on this page http://ferienhaus-fischland-ahrenshoop.de probably on the start page and others.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!