css样式支持左右滑动要点

div 包含 ul ,ul 包含 li

div宽度固定,ul 宽度随着li的可以无限增加,li 左右滑动的最小容器。

div 样式position:relative;width:xxpx;height:xxpx;

ul 样式 list-style: none; white-space: nowrap;position: absolute; top: 0; left: 0;margin: 0px; padding: 0px;

li 样式 display: inline-block; vertical-align: top;list-style: none;white-space: nowrap;

 li元素水平有间隙,需要在其父元素上加配置:font-size:0

滚动设置:

 1 $(".mini-docker-right-array").click(function(event){
 2             var p =  $(this).parent().parent();
 3             var appToScroll = p.find(".app-to-scroll");
 4             var ul = p.find(".node-scroll-container");
 5             var ulLeft = parseInt(ul.css("left"));
 6             var left = ulLeft;
 7             if(ul.width() + ul.position().left > appToScroll.width()){
 8                 left = ulLeft - appToScroll.width();
 9             }
10             ul.animate({
11                 "left": left + "px"
12             });
13             event.stopPropagation();
14         })
15         
16         $(".imagebutton-left-botton").click(function(event){
17             var p =  $(this).parent().parent();
18             var appToScroll = p.find(".app-to-scroll");
19             var ul = p.find(".node-scroll-container");
20             var ulLeft = parseInt(ul.css("left"));
21             var left = ulLeft = appToScroll.width();
22             if(left > 0){
23                 left = 0;
24             }
25             ul.animate({
26                 "left": left + "px"
27             });
28             event.stopPropagation();
29         })

猜你喜欢

转载自www.cnblogs.com/sxtg/p/9950565.html