Common JS image scrolling (seamless, smooth, up-down, left-side scrolling) code Daquan

Source: Internet
Author: User

 
<Head>
<----->
</Head>
<Body>

<! -- Scroll down to start the code -->
<Div id = "colee" style = "overflow: hidden; height: 253px; width: pixel;">
<Div id = "colee1">
<P> </p>
<P> </p>
<P> </p>
<P> </p>
<P> </p>
<P> </p>
<P> </p>
<P> </p>
<P> </p>
</Div>
<Div id = "colee2"> </div>
</Div>
<Script>
Var speed = 30;
Var colee2 = document. getElementById ("colee2 ");
Var colee1 = document. getElementById ("colee1 ");
Var colee = document. getElementById ("colee ");
Colee2.innerHTML = colee1.innerHTML; // clone colee1 to colee2
Function Marquee1 (){
// When rolling to the junction of colee1 and colee2
If (colee2.offsetTop-colee. scrollTop <= 0 ){
Colee. scrollTop-= colee1.offsetHeight; // jump to the top of the page
} Else {
Colee. scrollTop ++
}
}
Var MyMar1 = setInterval (Marquee1, speed) // set the timer
// When you move the mouse up, clear the timer to stop rolling.
Colee. onmouseover = function () {clearInterval (MyMar1 )}
// Reset the timer when you move the mouse away.
Colee. onmouseout = function () {MyMar1 = setInterval (Marquee1, speed )}
</Script>

<! -- Scroll up to end the code -->

 

<Br>

<! -- Below is the code to scroll down -->

<Div id = "colee_bottom" style = "overflow: hidden; height: 253px; width: pixel;">
<Div id = "colee_bottom1">
<P> </p>
<P> </p>
<P> </p>
<P> </p>
<P> </p>
<P> </p>
<P> </p>
<P> </p>
<P> </p>
</Div>
<Div id = "colee_bottom2"> </div>
</Div>
<Script>
Var speed = 30
Var colee_bottom2 = document. getElementById ("colee_bottom2 ");
Var colee_bottom1 = document. getElementById ("colee_bottom1 ");
Var colee_bottom = document. getElementById ("colee_bottom ");
Colee_bottom2.innerHTML = colee_bottom1.innerHTML
Colee_bottom.scrollTop = colee_bottom.scrollHeight
Function Marquee2 (){
If (colee_bottom1.offsetTop-colee_bottom.scrollTop> = 0)
Colee_bottom.scrollTop + = colee_bottom2.offsetHeight
Else {
Colee_bottom.scrollTop --
}
}
Var MyMar2 = setInterval (Marquee2, speed)
Colee_bottom.onmouseover = function () {clearInterval (MyMar2 )}
Colee_bottom.onmouseout = function () {MyMar2 = setInterval (Marquee2, speed )}
</Script>

<! -- Scroll down to end the code -->

<Br>

 

<! -- The following is the code for scrolling to the left -->

<Div id = "colee_left" style = "overflow: hidden; width: 500px;">
<Table cellpadding = "0" cellspacing = "0" border = "0">
<Tr> <td id = "colee_left1" valign = "top" align = "center">
<Table cellpadding = "2" cellspacing = "0" border = "0">
<Tr align = "center">
<Td> <p> </p> </td>
<Td> <p> </p> </td>
<Td> <p> </p> </td>
<Td> <p> </p> </td>
<Td> <p> </p> </td>
<Td> <p> </p> </td>
<Td> <p> </p> </td>
</Tr>
</Table>
</Td>
<Td id = "colee_left2" valign = "top"> </td>
</Tr>
</Table>
</Div>
<Script>
// When using div, ensure that colee_left2 and colee_left1 are on the same line.
Var speed = 30 // The greater the speed, the slower the speed.
Var colee_left2 = document. getElementById ("colee_left2 ");
Var colee_left1 = document. getElementById ("colee_left1 ");
Var colee_left = document. getElementById ("colee_left ");
Colee_left2.innerHTML = colee_left1.innerHTML
Function Marquee3 (){
If (colee_left2.offsetWidth-colee_left.scrollLeft <= 0) // offsetWidth is the visible width of the object
Colee_left.scrollLeft-= colee_left1.offsetWidth // scrollWidth indicates the width of the object's actual content, not the edge width.
Else {
Colee_left.scrollLeft ++
}
}
Var MyMar3 = setInterval (Marquee3, speed)
Colee_left.onmouseover = function () {clearInterval (MyMar3 )}
Colee_left.onmouseout = function () {MyMar3 = setInterval (Marquee3, speed )}
</Script>

<! -- Scroll to the left to end the code -->

<Br>

 

 

<! -- The following is the code for scrolling to the right -->

<Div id = "colee_right" style = "overflow: hidden; width: 500px;">
<Table cellpadding = "0" cellspacing = "0" border = "0">
<Tr> <td id = "colee_right1" valign = "top" align = "center">
<Table cellpadding = "2" cellspacing = "0" border = "0">
<Tr align = "center">
<Td> <p> </p> </td>
<Td> <p> </p> </td>
<Td> <p> </p> </td>
<Td> <p> </p> </td>
<Td> <p> </p> </td>
</Tr>
</Table>
</Td>
<Td id = "colee_right2" valign = "top"> </td>
</Tr>
</Table>
</Div>
<Script>
Var speed = 30 // The greater the speed, the slower the speed.
Var colee_right2 = document. getElementById ("colee_right2 ");
Var colee_right1 = document. getElementById ("colee_right1 ");
Var colee_right = document. getElementById ("colee_right ");
Colee_right2.innerHTML = colee_right1.innerHTML
Function Marquee4 (){
If (colee_right.scrollLeft <= 0)
Colee_right.scrollLeft + = colee_right2.offsetWidth
Else {
Colee_right.scrollLeft --
}
}
Var MyMar4 = setInterval (Marquee4, speed)
Colee_right.onmouseover = function () {clearInterval (MyMar4 )}
Colee_right.onmouseout = function () {MyMar4 = setInterval (Marquee4, speed )}
</Script>

<! -- Scroll to the right to end the code -->


</Body>
</Html>

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.