Horizontal scrolling of class marquee implemented by js

Source: Internet
Author: User

Copy codeThe Code is as follows:
<Script>
Var speed = 20;/* the greater the speed, the slower the speed */
Document. getElementById ('www _ qpsh_com2 '). innerHTML = document. getElementById ('www _ qpsh_com1'). innerHTML;

/* The two layers alternate back and forth */
Function Marquee (){
If (document. getElementById ('www _ qpsh_com2 '). offsetWidth-document.getElementById ('www _ qpsh_com'). scrollLeft <= 0)
Document. getElementById ('www _ qpsh_com '). scrollLeft-= document. getElementById ('www _ qpsh_com1'). offsetWidth;
Else {
Document. getElementById ('www _ qpsh_com '). scrollLeft ++;
}
Document. getElementById ('My _ marquee_info '). innerHTML = '';
Document. getElementById ('My _ marquee_info '). innerHTML + = 'div. scrollTop:' + document. getElementById ('www _ qpsh_com '). scrollLeft;
}
Var MyMar = setInterval (Marquee, speed );
Www_qpsh_com.onmouseover = function () {clearInterval (MyMar );}
Www_qpsh_com.onmouseout = function () {MyMar = setInterval (Marquee, speed );}
</Script>

DEMO code:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns =" http://www.w3.org/1999/xhtml "> <pead> <title> My Marquee Halign </title> </pead> <style>/* My Marquee CSS Start */. my_marquee_info {width: 200px; border: #987654 solid 1px; padding: 20px 3px 3px 2px; margin-top: 30px ;}. my_marquee_main {width: 200px; height: 160px; border: #234567 solid 1px; padding: 2px 3px 3px 2px; overflow: hidden ;}. my_marquee_div1 {width: 195px; border: Green solid 1px ;}. my_marquee_div2 {width: 195px; border: Red solid 1px;}/* My Marquee CSS End */</style> <body style = "text-align: center; "> <table align =" left "cellpadding =" 0 "cellspace =" 0 "border =" 0 "> <tr> <td id =" www_qpsh_com1 "valign =" top"> <table border = "0" cellpadding = "0" cellspacing = "10"> <tr> <td height = "96" align = "center" valign = "middle" style = "background-color: green; "title =" I am the first "> <center> training venue </center> </td> <td height =" 96 "align =" center "valign =" middle"> <center> casual tea club </center> </td> <td height = "96" align = "center" valign = "middle"> <center> club introduction </center> </td> <td height = "96" align = "center" valign = "middle"> <center> indoor arena and horse Room </center> </td> <td height = "96" align = "center" valign = "middle" style = "background-color: red; "title =" I am the last "> <center> farm </center> </td> </tr> </table> </td> <td id =" www_qpsh_com2 "valign =" top "> </td> </tr> </table> </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

Related Article

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.