效果如下:

js实现无缝滚动图

代码如下:

<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="utf-8">
  <style type = "text/css">
   ul, li { padding: 0; margin: 0; }
   li { list-style: none; }
   .box {
   width: 800px;
   height: 450px;
   margin: 50px auto;
   overflow: hidden; 
   position: relative;
   }
   .box span {
   width: 40px;
   height: 60px;   
   display: block;
   position: absolute;
   top: 225px;
   margin-top: -20px;
   cursor: pointer;
   z-index: 1;
   }
   .box #left {
 background: url('http://cdn.attach.qdfuns.com/notes/pics/201701/14/042311cbd7gbjd7sggkd2b.png') no-repeat;
 left: 0;
   }
   .box #right {
   background: url('http://cdn.attach.qdfuns.com/notes/pics/201701/14/042241w8z4hx4m4pjhyjzs.png') no-repeat;
   right: 0;
   }
   #ad {
   width: 4000px;
   height: 450px;
   position: absolute;
   }
   #ad li {
 float: left;
   }
  </style>
  <script type = "text/javascript">
   window.onload = function(){
   var ad = document.getElementById("ad");
   var timer = null;//管理定时器
   var leader = 0;
    //1秒之后再开启定时器
    timer = setTimeout(function(){
     timer = setInterval(autoAd,30);
    },1000);
   //开启定时器
   function autoAd(){   
   leader -=5;
   leader<=-3200"px";
   }
   //鼠标划入 关闭定时器
   ad.onmouseover = function() {   
   clearInterval(timer);
   }
   //鼠标离开 开启定时器
   ad.onmouseout = function(){
   timer = setInterval(autoAd,20);
   }
   }
  </script>
 </head>
 <body>
  <div class="box">  
  <ul id="ad">
  <li><img src="/UploadFiles/2021-04-02/042153lscsitwp7sszb6zs.jpg">

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!