开发者

jQuery Carousel scrolling

开发者 https://www.devze.com 2023-03-20 20:36 出处:网络
I just pinched this script from a tutorial. It does everything i need - steps along at multiple slides and selectable \'current\'

I just pinched this script from a tutorial. It does everything i need - steps along at multiple slides and selectable 'current'

It does however have an error whereby, if the step there are less slides than the step amount, it will not step at all.

<script language="javascript">
jQuery(function() {
    var step = 8; 
    var current = 10; 
    var maximum = jQuery('#thumb-nav-inner ul li').size(); 
    var visible = 8; 
    var speed = 500; 
    var liSize = 114;
    var carousel_height = 93;


    var ulSize = liSize * maximum;   
    var divSize = liSize * visible;  

    jQuery('#thumb-nav-inner ul').cs开发者_运维技巧s("width", ulSize+"px").css("left", -(current * liSize)).css("position", "absolute");

    jQuery('#thumb-nav-inner').css("width", divSize+"px").css("height", carousel_height+"px").css("visibility", "visible").css("overflow", "hidden").css("position", "relative"); 

    jQuery('#right-thumb-scroll').click(function() { 
        if(current + step < 0 || current + step > maximum - visible) {return; }
        else {
            current = current + step;
            jQuery('#thumb-nav-inner ul').animate({left: -(liSize * current)}, speed, null);
        }
        return false;
    });

    jQuery('#left-thumb-scroll').click(function() { 
        if(current - step < 0 || current - step > maximum - visible) {return; }
        else {
            current = current - step;
            jQuery('#thumb-nav-inner ul').animate({left: -(liSize * current)}, speed, null);
        }
        return false;
    });
});

Can anyone help with fixing this?

Thanks guys!


Haven't tested this, but I think the error lies with current + step > maximum - visible and current - step > maximum - visible. If there are less items available than should be visible it will always return true and thus not step! You should calculate a minimum and maximum value for those situations, which should be Math.min(maximum, maximum - visible).

0

精彩评论

暂无评论...
验证码 换一张
取 消