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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>淘宝轮播图</title> <style type="text/css"> *{ margin: 0; padding: 0; } .root{ width: 520px; height: 280px; border: #FFD700 3px solid; margin: 30px auto; position: relative; overflow: hidden; } .content{ width: 3120px; height: 280px; position: absolute; left: 0; } .content img{ float: left; } </style> </head> <body> <div class="root"> <div class="content"> <img src="img/t1.png"/> <img src="img/t2.jpg"/> <img src="img/t3.jpg"/> <img src="img/t4.jpg"/> <img src="img/t5.jpg"/> <img src="img/t1.png"/> </div> </div> </body> </html> <script src="js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript"> var imgIndex = 0; function autoChange(){ imgIndex++; $(".content").animate({ left: -imgIndex * 520, }, 800, "linear", function(){ if(imgIndex == 5){ imgIndex = 0; $(".content").css("left", "0"); } }) } var timer =setInterval(autoChange, 1200); </script>
|