forked from Chuyue0/javascript-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jq_scrollWall.html
53 lines (52 loc) · 1.31 KB
/
jq_scrollWall.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>jquery照片墙效果</title>
<style type="text/css">
*{margin: 0; padding: 0;}
/*img{display: block;}*/
#box{width: 500px; height: 90px; border: 1px solid red; font-size: 0; overflow:hidden; margin: 100px auto;}
#boxin{width:500%;}
#left,#right{float: left;}
</style>
<script src="jquery-1.12.0.min.js" type="text/javascript"></script>
</head>
<body>
<div id="box">
<div id="boxin">
<div id="left">
</div>
<div id="right"></div>
</div>
</div>
</body>
<script type="text/javascript">
var speed=40;
$box=$("#box"),
$left=$("#left"),
$right=$("#right");
var imgstr='';
for(var i=1;i<=6;i++){
imgstr+='<img src="img/wall_s'+i+'.jpg" alt="" />'
}
$left.append(imgstr);
right.innerHTML=left.innerHTML;
var timer=setInterval(fun, speed);
function fun(){
if(left.offsetWidth-box.scrollLeft<=0){
box.scrollLeft=0;
}else{
box.scrollLeft++;
}
}
$box.on({
mousemove:function(){
clearInterval(timer);
},
mouseout:function(){
timer=setInterval(fun, speed);
}
});
</script>
</html>