js图片的滑动

实现图片的无缝滚动就是要让你的图片集在一定时间里自动切换,那就需要js里的定时器来控制时间。

<!DOCTYPE html>
  <html lang="en">
   
   <head>
      <meta charset="UTF-8">
      <title>ZuiYangDan</title>
      <style>
          * {
              margin: 0;
             padding: 0;
             list-style: none;
         }
         
         #container {
             width: 100%;
             border: 1px solid #aaa;
             margin: 100px 0px;
         }
         
         #pictures {
             width: 100%;
             height: 520px;
             overflow: hidden;
             position: relative;
         }
         
         #ul1 {
             position: absolute;
             left: 0;
             top: 0;
             overflow: hidden;
         }
         
         #ul1 li {
             float: left;
             width: 700px;
             height: auto;
         }
         
         #ul1 li img {
             width: 700px;              height: auto;
          }
 
     </style>
 
 
<script>
         window.onload = function() {
             var oDiv = document.getElementById("pictures");
            var oUl = document.getElementById("ul1");
             var speed = -3;
           var oLi = document.getElementsByTagName("li");
 
             oUl.innerHTML += oUl.innerHTML;//先把图片增加一组
            oUl.style.width = oLi.length * oLi[0].offsetWidth + "px";
 
             function move() {
                if (oUl.offsetLeft < -oUl.offsetWidth / 2) {
                    oUl.style.left = "0";
               }
                oUl.style.left = oUl.offsetLeft + speed + "px";
             }
             var timer = setInterval(move, 30);
            oDiv.onmouseover = function() {
                 clearInterval(timer);
             };
             oDiv.onmouseout = function() {
                 timer = setInterval(move, 30);
             };
         }
 
     </script>
 
  </head>
 
 <body>
75     <div id="container">
76         <div id="pictures">
77             <ul id="ul1">
78                 <li><img src="https://www.yundapm.com/wp-content/uploads/2023/07/PULPING-PRINCIPLES.jpg" alt=""></li>
79                 <li><img src="https://www.yundapm.com/wp-content/uploads/2023/07/DRUM-PULPING-PROCESS-768x370-1.jpg" alt=""></li>
80                 <li><img src="https://www.yundapm.com/wp-content/uploads/2023/07/SHIPMENT-OF-THE-DRUM-1024x492-2.jpg" alt=""></li>
81                 <li><img src="https://www.yundapm.com/wp-content/uploads/2022/11/1-million-ton-high-grade-paperboard.jpg" alt=""></li>
90             </ul>
91         </div>
92     </div>
93 </body>
 
  </html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值