[JS] seamless and continuous image scrolling

Source: Internet
Author: User

[JS] seamless and continuous image scrolling)
Author: City Mu Ren Date:
Font size: medium or large
How can we achieve continuous (seamless continuous) scrolling between the first and last images?

Solution: A container demo that sets the width and hides content that exceeds its width. demo1 and demo2 are included, demo1 is the scrolling content, and demo2 is the direct clone copy of demo1, by constantly changing the scrolltop or scrollleft of demo1, you can directly jump back to the initial position when you scroll to the junction of demo1 and demo2. Because demo1 is the same as demo2, you cannot tell the beat moment, this achieves seamless rolling.
Seamless left-side continuous scrolling of imagesCode:

Program Code
<Div id = "Demo" style = "overflow: hidden; width: 100%; color: # ffffff;">
<Table cellpadding = "0" cellspacing = "0" border = "0">
<Tr> <TD id = "demo1" valign = "TOP" align = "center">
<Table cellpadding = "2" cellspacing = "0" border = "0">
<Tr align = "center">
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
</Tr>
</Table>
</TD>
<TD id = "demo2" valign = "TOP"> </TD>
</Tr>
</Table>
</Div>
<SCRIPT>
VaR speed = 2 // The greater the speed, the slower the speed.
Demo2.innerhtml = demo1.innerhtml
Function marquee (){
If (demo2.offsetwidth-demo. scrollleft <= 0)
Demo. scrollleft-= demo1.offsetwidth
Else {
Demo. scrollleft ++
}
}
VaR mymar = setinterval (marquee, speed)
Demo. onmouseover = function () {clearinterval (mymar )}
Demo. onmouseout = function () {mymar = setinterval (marquee, speed )}
</SCRIPT>

 

Code for seamless upward and continuous scrolling of images:

Program code
<Table width = "100%" border = 0>
<Tbody>
<Tr>
<TD align = middle>
<Div align = center> </div>
<Div id = demo style = "overflow: hidden; width: 160px; Height: 150px">
<Div id = demo1>
<Br/> <a href = "#" target = _ blank> </a>
<Br/> <a href = "#" target = _ blank> </a>
<Br/> <a href = "#" target = _ blank> </a>
<Br/> <a href = "#" target = _ blank> </a>
<Br/> <a href = "#" target = _ blank> </a> </div>
<Div id = demo2> </div>
<SCRIPT>
VaR speed = 2
Demo2.innerhtml = demo1.innerhtml
Function marquee (){
If (demo2.offsettop-demo. scrolltop <= 0)
Demo. scrolltop-= demo1.offsetheight
Else {
Demo. scrolltop ++
}
}
VaR mymar = setinterval (marquee, speed)
Demo. onmouseover = function () {clearinterval (mymar )}
Demo. onmouseout = function () {mymar = setinterval (marquee, speed )}
</SCRIPT>
</TD>
</Tr>
</Tbody>
</Table>

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.