jQuery Carousel滚动

时间:2011-07-18 11:04:50

标签: javascript jquery carousel

我只是从教程中捏了这个脚本。它做我需要的一切 - 在多个幻灯片和可选择的'当前'

的步骤

但它有一个错误,如果步骤中的步数少于步数,则它将不会步进。

<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').css("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;
    });
});

任何人都可以帮忙解决这个问题吗?

谢谢你们!

1 个答案:

答案 0 :(得分:0)

尚未对此进行测试,但我认为错误在于current + step > maximum - visiblecurrent - step > maximum - visible。如果可用的项目少于应该可见的项目,它将始终返回true,因此不会步骤!您应该计算这些情况的最小值和最大值,该值应为Math.min(maximum, maximum - visible)