I have been watching js animation these days, and today I got another carousel picture, which is implemented using pure js, but it has not been beautified. If you need it, beautify it yourself.
The following code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/"> <html xmlns="http:///1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>The effect of picture carousel</title> <style type="text/css"> * { margin: 0; padding: 0; text-decoration: none; } body { padding: 20px; } #container { position: relative; width: 600px; height: 400px; border: 3px solid #333; overflow: hidden; } #list { position: absolute; z-index: 1; width: 4200px; height: 400px; } #list img { float: left; width: 600px; height: 400px; } #buttons { position: absolute; left: 250px; bottom: 20px; z-index: 2; height: 10px; width: 100px; } #buttons span { float: left; margin-right: 5px; width: 10px; height: 10px; border: 1px solid #fff; border-radius: 50%; background: #333; cursor: pointer; } #buttons .on { background: orangered; } .arrow { position: absolute; top: 180px; z-index: 2; display: none; width: 40px; height: 40px; font-size: 36px; font-weight: bold; line-height: 39px; text-align: center; color: #fff; background-color: RGBA(0, 0, 0, .3); cursor: pointer; } .arrow:hover { background-color: RGBA(0, 0, 0, .7); } #container:hover .arrow { display: block; } #prev { left: 20px; } #next { right: 20px; } </style> </head> <body> <div > <div style="left: -600px;"> <img src="/cnblogs_com/rubylouvre/199042/o_s018.jpg" alt="Seamless scroll" /> <img src="/cnblogs_com/rubylouvre/199042/o_s018.jpg" alt="Seamless scroll" /> <img src="/cnblogs_com/rubylouvre/199042/o_s019.jpg" alt="Seamless scroll" /> <img src="/cnblogs_com/rubylouvre/199042/o_s020.jpg" alt="Seamless scroll" /> <img src="/cnblogs_com/rubylouvre/199042/o_s021.jpg" alt="Seamless scroll" /> <img src="/cnblogs_com/rubylouvre/199042/o_s022.jpg" alt="Seamless scroll" /> <img src="/cnblogs_com/rubylouvre/199042/o_s022.jpg" alt="Seamless scroll" /> </div> <div > <span index="1" class="on"></span> <span index="2"></span> <span index="3"></span> <span index="4"></span> <span index="5"></span> </div> <a href="javascript:;" rel="external nofollow" rel="external nofollow" class="arrow">&lt;</a> <a href="javascript:;" rel="external nofollow" rel="external nofollow" class="arrow">&gt;</a> </div> <script type="text/javascript"> =function(){ var container = ("container"); var list = ("list"); var buttons = ("buttons").getElementsByTagName('span'); var prev = ("prev"); var next = ("next"); var index = 1; function animate(offset){ var newLeft = parseInt() + offset; = newLeft + 'px'; if(newLeft<-3000){ = -600 +'px'; } if(newLeft>-600){ = -3000 + 'px'; } } function buttonsshow(){ for(var i =0; i<;i++){ if(buttons[i].className == 'on'){ buttons[i].className=''; } } buttons[index-1].className='on'; } = function(){ index-=1; if(index<1) { index=5; } buttonsshow(); animate(600); }; = function(){ index+=1; if(index>5){ index=1; } buttonsshow(); animate(-600); }; //Auto play var timer; function play(){ timer= setInterval(function(){ (); },1000) } play(); function stop(){ clearInterval(timer); } =stop; =play; for(var i=0; i<; i++){ ( function(i){ buttons[i].onclick=function(){ var clickindex= parseInt(('index')); var offset = 600*(index-clickindex); animate(offset); index = clickindex; buttonsshow(); } })(i); } } </script> </body> </html>
The above is the pure JS implementation carousel picture introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!