The important point is that scrollleft has been changing. The object has been moving and the reference is not moving.
Code:
Css:
#div1{Display:Black;width:110px;Height:50px;Line-height:50px;White-space:nowrap;Overflow:Hidden;Background-color:#a2a2a2;margin:15px;padding:5px 15px;}span{Display:Inline-block;Color:#fff;Padding-right:20px;}
Html:
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"Xml:lang= "en"><Head><MetaCharSet= "Utf-8"/><title>Mq</title> </Head> <Body> <DivID= "Div1"> <spanID= "Span1">Daily Coin Exclusive</span><spanID= "Span2"></span> </Div><spanID= "Span1">Daily Coin Exclusive Item A</span> </Body></HTML>
Js:
varDiv,span,span2,i,timer; functioninit () {setinterval (TTB,50); } functionTTB () {div= GetId (' Div1 '); Span= GetId (' Span1 '); Span2= GetId (' span2 '); Span2.innerhtml=span.innerhtml; if(Span.offsetwidth <=div.scrollleft) {Div.scrollleft-=Span.offsetwidth; } Else{div.scrollleft++; } } functiongetId (Id) {returndocument.getElementById (Id); } window.onload= init ();
Text automatically scrolls from left to right JS code