This article mainly shares the sample code for native JS to achieve the effect of running a horse lamp. It has good reference value. Let's take a look at it below. This article mainly shares the sample code for native JS to achieve the effect of running the horse lamp. It has good reference value. Let's take a look at it together with the small Editor.
The effect is as follows: (you can view the dynamic effect and add images in the case)
The Code is as follows:
《script》 var oUl=document.getElementsByTagName('ul')[0]; var lis=oUl.getElementsByTagName('li'); oUl.innerHTML+=oUl.innerHTML; oUl.style.width=lis.length*lis[0].offsetWidth+'px'; var left=null; var timer=setInterval(function(){ left-=3; if(left<-oUl.offsetWidth/2){ left=0; } oUl.style.left=left+'px' },10)《script》
For more articles about how native JS achieves the running horse lamp effect, refer to the PHP Chinese network!