javascript - 查看最后一项时停止滚动 - 使用 jQuery

标签 javascript jquery

我有一个动态项目列表,它具有像幻灯片一样的滚动效果,当显示列表的最后一个项目时,我无法使用箭头设置滚动限制。

知道如何在查看最后一项时停止滚动吗?示例如下: JSFIDDLE

    $('.nextArrow').click(function() {
        //Animate the images to next slide
        $('.thumbs li:eq(0)').animate({"margin-top": "-=80"}, 500);             
    });

    $('.prevArrow').click(function() {
        var marginTopValue = $('.thumbs li:eq(0)').css('margin-top');
        //Animate the image to previous slide
        if (marginTopValue == '0px') {

        } else {
            $('.thumbs li:eq(0)').animate({"margin-top": "+=80"}, 500);
        };
    });

最佳答案

改变

$('.nextArrow').click(function() {
    //Animate the images to next slide
    $('.thumbs li:eq(0)').animate({"margin-top": "-=80"}, 500);             
});

$('.nextArrow').click(function() {
        //Animate the images to next slide
  var marginTopValue = parseInt($('.thumbs li:eq(0)').css('margin-top').replace('px', ''));
  if (marginTopValue >= (0-$('.thumbs')[0].scrollHeight))
  {
        $('.thumbs li:eq(0)').animate({"margin-top": "-=80"}, 500);
  }
    });

JSFIDDLE在这里!

关于javascript - 查看最后一项时停止滚动 - 使用 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39493637/

相关文章:

javascript - 关闭 SlideToggle 时如何更改/删除类

javascript - 从 TamperMonkey 打开 jQuery Accordion

javascript - 如何在图像之间添加微妙的过渡?

javascript - Javascript 中的 NaN

javascript - 如何让Gmaps.js在动态标记javascript之间绘制路线?

javascript - 在哪里可以下载独立的 Microsoft 脚本编辑器?

javascript - jQuery 隐藏/显示不起作用,不像 JS 函数

javascript - 如何使用搜索过滤器形式搜索 JSON 数组?

javascript - 使用窗口大小JavaScript显示和隐藏div?

jquery - 在 iOS 上的 Safari 和 Chrome 中只允许数字和冒号