jQuery 轮播滚动

发布于 2024-11-24 22:20:19 字数 1472 浏览 1 评论 0原文

我刚刚从教程中摘取了这个脚本。它完成了我需要的一切 - 在多个幻灯片和可选择的“当前”上进行操作,

但是它确实有一个错误,如果步骤中的幻灯片少于步骤数量,则它根本不会步进。

<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;
    });
});

有人能帮忙解决这个问题吗?

谢谢你们!

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

Can anyone help with fixing this?

Thanks guys!

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

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

发布评论

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

评论(1

似梦非梦 2024-12-01 22:20:19

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

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).

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