Posted in Javascript onOctober 28, 2019
本文实例为大家分享了js实现图片无缝循环轮播的具体代码,供大家参考,具体内容如下
代码如下
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> #container{ overflow:hidden; width:400px; height:300px; margin:auto; } #front,#container{ display:flex; flex-direction:row; } #container img{ width:400px; height:300px; } </style> </head> <body> <div id="container"> <div id="front"> <img src="k2.jpg" alt=""> <img src="k1.jpg" alt="" > <img src="k3.jpg" alt=""> <img src="k4.jpg" alt=""> </div> <div id="back"><img src="k5.jpg" alt=""></div> </div> </body> <script> front.style="position:relative;left:0px;"; back.style="position:relative;left:0px;"; setInterval(moveimg,100); var fleft,bleft; function moveimg(){ fleft = parseInt(front.style.left); bleft = parseInt(back.style.left); if(fleft == -1600){ front.style.left = 400+"px"; fleft = parseInt(front.style.left); } if(bleft == -2000) { back.style.left = 0+"px"; bleft = parseInt(back.style.left); } front.style.left = (fleft-10)+"px"; back.style.left = (bleft-10)+"px"; } </script> </html>
更多关于轮播图效果的专题,请点击下方链接查看学习
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。
js实现图片无缝循环轮播
- Author -
KD-倘若没有倘若声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@