JS 实现可停顿的垂直滚动

 1  var ScrollMiddle = {
 2          'Odiv':document.getElementById('comment'), // 目标DOM        
 3          'Oli': document.getElementById('comment').getElementsByTagName('li'), 
 4          'times':30,            // 配置滚动时间                                                
 5          'delay':1000,        // 配置暂停的时间                                
 6          inint:function(){
 7              this.size = this.Oli.length;
 8              this.height = 59;
 9              this.countHeight =this.size * this.height;
10              this.Odiv.innerHTML+=this.Odiv.innerHTML;
11              this.timer = null;
12          },
13          scroll:function(){
14              var _this = this;
15              _this.inint();
16              function scrolls(){
17 
18                  var scrollValue = _this.Odiv.scrollTop;
19                  var sub_timer = null;
20                  var num=0;
21                  if(scrollValue>=_this.countHeight){
22                      _this.Odiv.scrollTop = 0;
23                  }else{
24                      _this.Odiv.scrollTop++;
25                      if(scrollValue%_this.height==0){
26                          clearInterval(_this.timer)
27                          function delay(){
28                              num++;
29                              if(num==3){
30                                  num=0;
31                                  clearInterval(sub_timer);
32                                  sub_timer = null;
33                                  clearInterval(_this.timer)
34                                  _this.timer = setInterval(scrolls,_this.times);
35                                  return false;
36                              }
37                          }
38                          sub_timer = setInterval(delay,_this.delay)
39                      }
40                  }
41              }
42              this.timer = setInterval(scrolls,_this.times);
43          }
44      }

调用方法:

ScrollMiddle.scroll();

HTML 结构:

<ul id="comment">
    <li></li>
    ......
</ul>

CSS结构:

#comment{
   width:200px;
   height:200px;
   overflow:hidden;   
}

 

转载于:https://www.cnblogs.com/HCJJ/p/5197681.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值