Home > Article > WeChat Applet > How to achieve intermittent circular scrolling effect of JS text
This time I will show you how to implement the intermittent cyclic scrolling effect of JS text. What are the precautions for realizing the intermittent cyclic scrolling effect of JS text. The following is a practical case, let’s take a look.
The specific code is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>www.jb51.net - 间歇循环滚动</title> <style> #box{ height:240px; width:300px; margin:0 auto; border:1px solid #0066FF; overflow:hidden; padding-bottom:20px; } #box li{ color:#333; height:24px; } #box ul{ margin:0; padding:0; } </style> </head> <body> <p id="box"> <ul id="con1"> <li>PHP1</li> <li>PHP2</li> <li>PHP3</li> <li>PHP4</li> <li>PHP5</li> <li>PHP6</li> <li>PHP7</li> <li>PHP8</li> <li>PHP9</li> </ul> </p> <script> var area=document.getElementById("box"); area.innerHTML+=area.innerHTML; var liHeight=24; area.scrollTop=0; var delay=2000; var speed=50; var time; function starMove(){ area.scrollTop++; time=setInterval("scrollUp()",speed); } function scrollUp(){ if(area.scrollTop%liHeight==0){ clearInterval(time); setTimeout("starMove()",delay); }else{ area.scrollTop++; if(area.scrollTop>=area.offsetHeight/2){ area.scrollTop=0; } } } setTimeout("starMove()",delay); </script> </body> </html>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How to use the encapsulation function of JS motion buffering effect
Detailed explanation of asynchronous loading of JavaScript
The above is the detailed content of How to achieve intermittent circular scrolling effect of JS text. For more information, please follow other related articles on the PHP Chinese website!