1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title>Title</title>6 </Head>7 <Body>8 <DivID= "I1"style= "width:400px;9 height:300px;Ten Position:absolute; One left:50%; A top:50%; - margin-left: -200px; - margin-top: -150px; ">welcome Zinming to visit our guide the </Div> - <Script> - functionf () { - //get the corresponding div,document according to the ID meaning is to go to the entire HTML document to find, getElementById is based on the ID + varTag=document.getElementById ('I1') - //get the text in the Div, note that the InnerText method has no parentheses + varcontent=Tag.innertext A //get the first text of this string at varZ=Content.charat (0) - //get this text in addition to the first word, with substring give it a starting position - varL=content.substring (1, Content.length) - //Put the first character on the last one and stitch it up. - varnew_content=L+Z - //Replace the text in the div with the newly generated new_content in Tag.innertext=new_content - } to //SetInterval is a timer, the first parameter is the content to be executed, the second parameter is the execution interval, in milliseconds + SetInterval ('f ()', -) - </Script> the * </Body> $ </HTML>
The text in the JavaScript settings Div scrolls to achieve the scrolling effect.