Jquery 垂直列表滑块不会重复多次

发布于 2024-09-10 12:15:29 字数 1447 浏览 8 评论 0原文

我有一个垂直滑块,除非需要滚动多次,否则效果很好。

查看滑块

代码

$(document).ready(function() {
    var speed = 1050;
    var elementHeight = 106;
    var countElements = $('#portfolio-navigation ul li');
    var numberElements = countElements.length;
    var totalHeight = numberElements * elementHeight;
    var containerHeight = 742;

    var currentPlace = elementHeight * 7;
    var currentDifference = 0;
    $("#up").addClass("nogo"); 
    $("#down").click(function(event) {
        $("#down").addClass("nogo");
        $("#up").removeClass("nogo");
        event.preventDefault();
        if (currentPlace >= totalHeight) { 
        } else { // Ellers, continue!
        currentPlace += elementHeight;
        currentDifference += elementHeight; 
            $("#portfolio-navigation ul").animate({ top: "-510px"}, speed );
        }   
    });
    $("#up").click(function(event) {
         $("#down").removeClass("nogo");
         $("#up").addClass("nogo");
        event.preventDefault();

        if (currentPlace <= containerHeight) { 
        } else { // Ellers, continue!
        currentPlace -= elementHeight;
        currentDifference -= elementHeight; 
            $("#portfolio-navigation ul").animate({ top: 0 + "px"}, speed );
        }   
    });
});

这是我希望能够使滑块向下滚动多次的 。

有什么想法吗?

干杯 尼克

I have a vertical slider that works well except when it needs to scroll more than once.

view slider

This is the code

$(document).ready(function() {
    var speed = 1050;
    var elementHeight = 106;
    var countElements = $('#portfolio-navigation ul li');
    var numberElements = countElements.length;
    var totalHeight = numberElements * elementHeight;
    var containerHeight = 742;

    var currentPlace = elementHeight * 7;
    var currentDifference = 0;
    $("#up").addClass("nogo"); 
    $("#down").click(function(event) {
        $("#down").addClass("nogo");
        $("#up").removeClass("nogo");
        event.preventDefault();
        if (currentPlace >= totalHeight) { 
        } else { // Ellers, continue!
        currentPlace += elementHeight;
        currentDifference += elementHeight; 
            $("#portfolio-navigation ul").animate({ top: "-510px"}, speed );
        }   
    });
    $("#up").click(function(event) {
         $("#down").removeClass("nogo");
         $("#up").addClass("nogo");
        event.preventDefault();

        if (currentPlace <= containerHeight) { 
        } else { // Ellers, continue!
        currentPlace -= elementHeight;
        currentDifference -= elementHeight; 
            $("#portfolio-navigation ul").animate({ top: 0 + "px"}, speed );
        }   
    });
});

I want to be able to make the slider scroll down more than once.

Any ideas?

Cheers
Nik

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

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

发布评论

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

评论(1

云雾 2024-09-17 12:15:30

我不确定我是否理解你的问题,但通常你会想要上下移动 UL,直到它到达列表的末尾。当您有固定高度的容器时,这很容易做到。只需在下一个按钮的动画中减去 510px,而不是将其设置为 -510px。之后,使用totalheight和containerheight变量来确定何时禁用按钮(我建议使用if/else)语句,而不是添加和删除类)。

I'm not sure I understand your question, but generally you would want to shift the UL up and down until it it gets to the end of the list. This is easy enough to do when you have a fixed-height container. Just subtract 510px in your animation on the next button instead of setting it to -510px. After that, use your totalheight and containerheight variables to figure out when to disable the buttons (I would suggest using if/else) statements instead of adding and removing classes).

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