Text automatically scrolls from left to right JS code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.