Thoroughly understand JS seamless code scrolling

Source: Internet
Author: User

I have to scroll through the code and it's seamless for half a day.
We are determined to solve this problem. It is not difficult to study the code below:

Program code

Copy codeThe Code is as follows: <div id = demo style = overflow: auto; height: 180; width: 200; background: #009900; color: #006600>
<Table align = top>
<Tr>
<Td id = demo1 valign = top>

<P> aaaaaaaaaaa </p>
<P> aaaaaaaaaaa </p>
<P> aaaaaaaaaaa </p>
<P> aaaaaaaaaaa </p>
<P> aaaaaaaaaaa </p>
<P> aaaaaaaaaaa </p>


</Td>
</Tr>
<Tr>
<Td id = demo2 valign = top> </td>
</Tr>
</Table>

</Div>
<Script>
Var speed = 15
Demo2.innerHTML = demo1.innerHTML // clone demo1 to demo2
Function Marquee (){
If (demo2.offsetHeight-demo. scrollTop <= 0) // when rolling to the junction of demo1 and demo2
Demo. scrollTop-= demo1.offsetHeight // The demo jumps to the top
Else {
Demo. scrollTop ++ // if it is horizontal, change all height top to width left.
}
}
Var MyMar = setInterval (Marquee, speed) // set the timer
Demo. onmouseover = function () {clearInterval (MyMar)} // clear the timer when you move the cursor up to stop scrolling.
Demo. onmouseout = function () {MyMar = setInterval (Marquee, speed)} // reset the timer when you move the cursor away
</Script>



Copy to an HTM file to run.

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.