setInterval的问题

buyue__ 2016-06-17 11:07:10
页面链接
http://demo.sc.chinaz.com//Files/DownLoad/webjs1/201312/jiaoben1836/



想要的效果:每滑动完一行就停顿一会儿再继续滑动
应该怎样改
...全文
150 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Go 旅城通票 2016-06-17
  • 打赏
  • 举报
回复
每一行高度一样吧,一样你就判断下滚动距离达到一行高度后停一下,再启动计时器继续滚动
        (function ($) {
            $.fn.myScroll = function (options) {
                //默认配置
                var defaults = {
                    speed: 40,  //滚动速度,值越大速度越慢
                    rowHeight: 24, //每行的高度
                    delay: 1000 //滚动每行后停留多少时间,单位ms
                };

                var opts = $.extend({}, defaults, options), intId = [],delayId=[];

                function startAnimate(i,_this) {
                    intId[i] = setInterval(function () {
                        if (_this.find("ul").height() <= _this.height()) {
                            clearInterval(intId[i]);
                        } else {
                            marquee(_this, opts.rowHeight, i);
                        }
                    }, options.speed);
                }


                function marquee(obj, step,i) {
                    obj.find("ul").animate({
                        marginTop: '-=1'
                    }, 0, function () {
                        var s = Math.abs(parseInt($(this).css("margin-top")));
                        if (s >= step) {
                            clearInterval(intId[i]);
                            delayId[i] = setTimeout(function () { startAnimate(i, obj); }, opts.delay);

                            $(this).find("li").slice(0, 1).appendTo($(this));
                            $(this).css("margin-top", 0);
                        }
                    });
                }

                this.each(function (i) {
                    var _this = $(this);
                    startAnimate(i, _this);
/////
                    _this.hover(function () { clearTimeout(delayId[i]); clearInterval(intId[i]); }, function () { startAnimate(i, _this); });

                });

            }

        })(jQuery);
php_wsd 2016-06-17
  • 打赏
  • 举报
回复
向上滑动的距离正好等于这个高度

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧