Image or text scroll up and down [JS scroll up, JS scroll down, JS scroll left, JS scroll to the right]

Source: Internet
Author: User

Note: When you scroll up or down, the content height in cell demo1 must be greater than the height set in demo to scroll infinitely.
When you scroll left or right, the content width in the cell demo1 must be greater than the width set in the demo to scroll infinitely.
I. Scroll up and down
1. displayed content

Code

<Div id = "demo" style = "OVERFLOW: hidden; WIDTH: 200px; HEIGHT: 100px;">
<Table border = "0" cellpadding = "0" cellspacing = "0">
<Tr>
<Td id = "demo1"> <table width = "100%" height = "99" border = "0" cellpadding = "0" cellspacing = "0">
<Tr>
<Td> 1 </td>
</Tr>
<Tr>
<Td> 2 </td>
</Tr>
<Tr>
<Td> 3 </td>
</Tr>
</Table> </td>
</Tr>
<Tr>
<Td id = "demo2"> </td>
</Tr>
</Table>
</Div>

2. Scroll up JS
Code

<SCRIPT>
Var speed = 30
Var MyMarh = setInterval (Marqueeh, speed)
Demo2.innerHTML = demo1.innerHTML
// The principle is to constantly enter demoh1 content in demoh2, and then clear invisible content
// Use a table with two rows and one column. Put another table with content loaded in the previous column, which is defined as demoh1. The next column is an empty TD and is defined as demoh2.
// SPEED is used to control the SPEED.
Demo. onmouseover = function () {clearInterval (MyMarh )}
Demo. onmouseout = function () {MyMarh = setInterval (Marqueeh, speed )}
Function Marqueeh (){
If (demo2.offsetHeight-demo. scrollTop <= 0)
Demo. scrollTop-= demo1.offsetHeight
Else {
Demo. scrollTop ++
}
}
</SCRIPT>

3. Scroll down JS
Code

<Script>
Var speed = 30
Demo2.innerHTML = demo1.innerHTML
Demo. scrollTop = demo. scrollHeight
Var MyMar = setInterval (Marquee, speed)

Demo. onmouseover = function () {clearInterval (MyMar )}
Demo. onmouseout = function () {MyMar = setInterval (Marquee, speed )}
Function Marquee (){
If (demo1.offsetTop-demo. scrollTop> = 0)
Demo. scrollTop + = demo2.offsetHeight
Else {
Demo. scrollTop --
}
}
</Script>

2. Scroll left and right
1. display content
Code

<Div id = "demo" style = "overflow: hidden; height: 100px; width: 200px;">
<Table cellpadding = "0" cellspace = "0" border = "0">
<Tr>
<Td id = "demo1"> <table width = "200" border = "0" cellspacing = "0" cellpadding = "0">
<Tr>
<Td> 1 </td>
<Td> 2 </td>
<Td> 3 </td>
</Tr>
</Table> </td>
<Td id = "demo2"> </td>
</Tr>
</Table>
</Div>

2. scroll to the left of JS
Code

<Script>
Var speed = 30
Var MyMar = setInterval (Marquee, speed)
Demo2.innerHTML = demo1.innerHTML
Demo. onmouseover = function () {clearInterval (MyMar )}
Demo. onmouseout = function () {MyMar = setInterval (Marquee, speed )}
Function Marquee (){
If (demo2.offsetWidth-demo. scrollLeft <= 0)
Demo. scrollLeft-= demo1.offsetWidth
Else {
Demo. scrollLeft ++
}
}
</Script>

3. Scroll JS to the right
Code

<Script>
Var speed = 30
Var MyMar = setInterval (Marquee, speed)
Demo2.innerHTML = demo1.innerHTML
Demo. onmouseover = function () {clearInterval (MyMar )}
Demo. onmouseout = function () {MyMar = setInterval (Marquee, speed )}
Function Marquee (){
If (demo. scrollLeft <= 0)
Demo. scrollLeft + = demo2.offsetWidth
Else {
Demo. scrollLeft --
}
}
</Script>

 

Very good network disk (http://ww618.com/-wangwang618 wish you every day, every day .))

 

 

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.