点击(此处)折叠或打开
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>Scroll Picture</title>
- <style type="text/css">
- #innerbox{
- outline:1px solid red;
- width: 3000px;
- height: 400px;
-
-
-
- }
- #picture1{
- width: 600px;
- height: 400px;
- /*outline: 1px solid greenyellow;*/
- float: left;
-
- }
- #alerts{
- width: 600px;
- height: 400px;
- outline: 1px solid black;
-
- margin: 0 auto;
-
-
- overflow:hidden;
-
- }
- </style>
- </head>
- <body>
- <div id="alerts">
- <div id="innerbox">
- <div id="picture1"><img src="img/10.jpg" alt="" /></div>
- <div id="picture1"><img src="img/8.jpg" alt="" /></div>
- <div id="picture1"><img src="img/7.jpg" alt="" /></div>
- <div id="picture1"><img src="img/9.jpg" alt="" /></div>
- <div id="picture1"><img src="img/10.jpg" alt="" /></div>
- </div>
- </div>
- <script type="text/javascript">
- var alerts = document.getElementById("alerts");
- // console.log(alert);
- var innerbox = document.getElementById("innerbox");
-
- // console.log("innerbox");
- var i=0;
-
- //计时器与函数包装到一起 图片没0.01秒进行左移动
- var b=setInterval(
- function fn(){
- i-=2;
- //给innerbox的左边距赋值 ,一旦超出-2400,那么变量就要重置了
- innerbox.style.marginLeft=i+'px';
-
- if(i<-2400){
- i=0;
- }
- //鼠标化出的效果,重新启动计时器
- alerts.onmouseout= function(){
- b=setInterval(fn,1);
- }
-
- }
- ,1);
- //鼠标划上的效果,清除启动计时器
- alerts.onmouseover=function(){
- clearInterval(b);
- }
-
-
-
-
-
-
- </script>
-
- </body>
- </html>