JavaScript example

1 The first character of a dynamic string moves to the end after 500 milliseconds, forming a dynamic effect

 

The source code is as follows:

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6 </head>
 7 <body>
 8 <div id="i1">热烈欢迎陈凯莅临指导</div>
 9 <script>
10 
11     /*
12      tag=document.getElementById('i1')
 13       <div id=​"i1">​welcome nod​</div>
​ 14       tag.innerText
 15       "welcome nod"
 16       */ 
17      /* 
18       scroll characters
 19       */ 
20      function func() {
 21          // Get i1de content 
22          var tag = document.getElementById( ' i1 ' );
 23          // Get text content 
24          var content = tag.innerText;
 25          // Remove the first character 
26          var f =content.charAt( 0 );
 27          var l = content.substring( 1 , content.length);
 28          // Ping 
29          var new_content = l + f;
 30          // Reassign innerText to 
31          tag.innerText = new_content;
 32      }
 33  
34      setInterval( ' func() ' , 300 )
 35  </ script > 
36  </ body > 
37  </html>
View Code

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325077388&siteId=291194637