jquery cycle plugin, nested slideshow, 'after' option or testing for first and last image

拥有回忆 提交于 2019-12-06 06:29:51

I think this is what you wanted (edited your example): http://jsfiddle.net/m8AFG/18/

$(document).ready(function() {
    // init and stop the inner slideshows
    var inners = $('.inner-slideshow').cycle().cycle('stop');
    var slideshow = $('#slideshow').cycle({
        fx: 'fade',
        speed: 'fast',
        timeout: 0,
        pager: '#nav',
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
            return '#nav li:eq(' + (idx) + ') a';
        },
        before: function() {
            // stop all inner slideshows
            inners.cycle('stop');
            // start the new slide's slideshow
            $(this).cycle({
                fx: 'scrollHorz',
                speed: 'fast',
                timeout: 0,
                prev: '#prev',
                next: '#next',
                nowrap: 1,
                after: function() {
                    $('#prev').removeClass('opac');
                    $('#next').removeClass('opac');
                    var countImg = $(this).siblings().size();
                    if ($(this).index() == 0) $('#prev').addClass('opac');
                    if ($(this).index() == countImg) $('#next').addClass('opac');
                }
            });
        }
    });
});

added css opacity and the jquery and cycle script link, and it works fine

Greetings, Michael

It would be helpful to know what plugin you are using, but most slider plugins have a parameter that you can add a function to, that will be called every time the actual sliding happens, something like 'onChange'. If this plugin has such a feature you could use some simple Javascript to either directly manipulate the CSS or the elements, or add a class to them to allow you to manipulate them in your CSS.

So you would need to know the current index - looks like 'idx' might provide that, and then you would do something like (pseudo code)

if(currentSlideNumber == slides.length){ 
    //Reduce opacity of next tab
}else if(currentSlideNumber == 1){
    //Reduce opacity of previous tab
}

Where 'currentSlideNumber' is the current index, and slides.length counts the number of slides - in Javascript that would be:

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