我是靠谱客的博主 无聊面包,这篇文章主要介绍横向滚动插件,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(function ( $ ) { $.fn.ilscroll=function(options){ var settings = $.extend({ s:45 }, options ); $this=this; $children=this.children(); $parent=this.parent(); $count=$children.size(); $margin=parseInt($children.css('margin-left'))+parseInt($children.css('margin-right')); $childrenwidth=$children.width()+$margin; $parentwidth=$parent.width(); $width=($count*$childrenwidth); if($width<$parentwidth){ return false; } $clone= $children.clone(); this.prepend($clone); this.width($width*2); $inter= setInterval(function(){ $marginleft=$this.css('margin-left'); $marginleft= parseInt($marginleft); $childh= parseInt($this.children().width()); if(Math.abs($marginleft)>=$width){ $this.css('margin-left',"0px"); }else{ $this.css('margin-left',$marginleft-1+"px"); } },settings.s); this.on('mouseover',function(){ clearInterval($inter); }); this.on('mouseout',function(){ $inter=setInterval(function(){ $marginleft=$this.css('margin-left'); $marginleft= parseInt($marginleft); $childh= parseInt($this.children().width()); if(Math.abs($marginleft)==$width){ $this.css('margin-left',"0px"); }else{ $this.css('margin-left',$marginleft-1+"px"); } },settings.s); }); }; }( jQuery ));

 当子元素不比父元素宽时,不会发生滚动。

使用

$('.foo').ilscroll()

一个参数s用于控制速度.

修改用于应对margin-auto

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(function ( $ ) { $.fn.ilscroll=function(options){ var settings = $.extend({ s:45 }, options ); $this=this; $children=this.children(); $parent=this.parent(); $count=$children.size(); $marginleft=$children.css('margin-left')=='auto'?0:parseInt($children.css('margin-left')); if($children.css){ } $children.css('margin-left','0px'); $children.css('margin-right','0px'); $margin=parseInt($children.css('margin-left'))+parseInt($children.css('margin-right')); $childrenwidth=parseInt($children.width())+$margin; $parentwidth=parseInt($parent.width()); $width=($count*$childrenwidth); if($width<$parentwidth){ return ; }else{ $clone= $children.clone(); this.prepend($clone); this.width($width*2); } $inter= setInterval(function(){ $marginleft=$this.css('margin-left'); if($marginleft==='auto'){ $marginleft=0; }else{ $marginleft=parseInt($marginleft); } $childh= parseInt($this.children().width()); if(Math.abs($marginleft)>=$width){ $this.css('margin-left',"0px"); }else{ $this.css('margin-left',(($marginleft)-1)+"px"); } },settings.s); this.on('mouseover',function(){ clearInterval($inter); }); this.on('mouseout',function(){ $inter=setInterval(function(){ $marginleft=$this.css('margin-left'); $marginleft= parseInt($marginleft); $childh= parseInt($this.children().width()); if(Math.abs($marginleft)==$width){ $this.css('margin-left',"0px"); }else{ $this.css('margin-left',$marginleft-1+"px"); } },settings.s); }); }; }( jQuery ));

 

转载于:https://www.cnblogs.com/zuoxiaobing/p/3623095.html

最后

以上就是无聊面包最近收集整理的关于横向滚动插件的全部内容,更多相关横向滚动插件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(62)

评论列表共有 0 条评论

立即
投稿
返回
顶部