当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JavaScript无缝滚动效果的实例代码

JavaScript无缝滚动效果的实例代码

2019年03月20日  | 移动技术网IT编程  | 我要评论
废话不多说了,直接给大家贴代码了,具体代码如下所示: <!doctype html public "-//w3c//dtd xhtml 1.0 tran

废话不多说了,直接给大家贴代码了,具体代码如下所示:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>document</title>
<style type="text/css">
  * {
  padding: 0;
  margin: 0;
  }
 .box {
 width: 600px;
 height: 200px;
 margin: 60px auto;
 overflow: hidden;
 position: relative;
 }
 ul {
  list-style-type: none;
  width: 2000px;
  position: absolute;
  top: 0;
  left: 0;
 }
 li {
  float: left;
 }
</style>
</head>
<body>
<div class="box" id="box">
 <ul id="gun">
 <li><img src="01.jpg" alt="" /></li>
 <li><img src="02.jpg" alt="" /></li>
 <li><img src="03.jpg" alt="" /></li>
 <li><img src="04.jpg" alt="" /></li>
 <li><img src="01.jpg" alt="" /></li>
 <li><img src="02.jpg" alt="" /></li>
 </ul>
 <script type="text/javascript">
       var box = document.getelementbyid("box");
       var gun = document.getelementbyid("gun");
       
       function $(i){
       return document.getelementsbytagname("img")[i];
       }
       var num = 0;
       all();
       function all(){
      var shi= setinterval(fun,5);
      gun.onmouseover=function (){
         clearinterval(shi);
      }
      gun.onmouseout=function (){
         all();
      }
      function fun(){
      if(num<=-1200){
          num=0;
      }else{
         gun.style.left=num+"px";
            num--;
          }  
          }
        } 
 </script>
</div>
</body>
</html>

以上所述是小编给大家介绍的javascript无缝滚动效果的实例代码,希望对大家有所帮助

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网