JavaScript轮播图简单制作方法

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <script src="https://www.jb51.net/js/jquery.js"></script> <style> .container{ position: absolute; left: 0; top:0; width: 100%; overflow: hidden; border:1px solid #c3c3c3; border-radius: 4px; } .block1{ margin:0; padding: 0; display: inline-block; height: 400px; background-color: #008800; } .block2{ margin:0; padding: 0; display: inline-block; height: 400px; background-color: #ffff00; } .block3{ margin:0; padding: 0; display: inline-block; height: 400px; background-color: #FF9900; } </style> </head> <body> <div> <div></div> <div></div> <div></div> </div> </body> <script> var wt=window.innerWidth; $(".block1").css({width:wt}); $(".block2").css({width:wt,left:wt}); $(".block3").css({width:wt,left:wt*2}); var aa=setInterval(function(){ $(".block1").css({left:parseFloat($(".block1")[0].style.left)-1}); $(".block2").css({left:parseFloat($(".block2")[0].style.left)-1}); $(".block3").css({left:parseFloat($(".block3")[0].style.left)-1}); if($(".block3")[0].style.left=="0px"){ // clearInterval(aa); // 清除循环滚动 $(".block1").css({left:0}) $(".block2").css({left:wt}) $(".block3").css({left:wt*2}) } },2) </script> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwzsyz.html