Js image seamless scrolling code

Source: Internet
Author: User

I used to write a jquery scroll between left and right. Now I want to achieve seamless scrolling of JavaScript.

In an example on the Internet, I feel that the rolling process is unstable and the process is getting faster. Below is the code I modified:

Js:

<Script>

Var speed = 20 // The greater the speed, the slower the speed.

Var www_qpsh_com2 = null;

Var www_qpsh_com1 = null;

Var www_qpsh_com = null;

Var MyMar = null;

Function load (){

Www_qpsh_com2 = document. getElementById ("www_qpsh_com2 ");

Www_qpsh_com1 = document. getElementById ("www_qpsh_com1 ");

Www_qpsh_com = document. getElementById ("www_qpsh_com ");

Var len = document. getElementById ("table"). getElementsByTagName ("td"). length;

If (len> 4) {// when there are fewer than four images in the image, the image does not scroll because the total width of the image is smaller than the width of the display box.

Www_qpsh_com2.innerHTML = www_qpsh_com1.innerHTML; // copy the content in 1 to this id for seamless operation.

Marquee ();

}

}

Function over (){

ClearTimeout (MyMar );

}

Function out (){

MyMar = setTimeout ("Marquee ()", speed );

}

Function Marquee (){

If (www_qpsh_com2.offsetWidth-www_qpsh_com.scrollLeft <= 0)

Www_qpsh_com.scrollLeft-= www_qpsh_com1.offsetWidth

Else {

Www_qpsh_com.scrollLeft ++;

}

MyMar = setTimeout ("Marquee ()", speed );

}

</Script>

Jsp page:

<Div id = www_qpsh_com onmouseout = "out ()">

<Table align = left cellpadding = 0 cellspace = 0 border = 0>

<Tr>

<Td id = www_qpsh_com1 valign = top>

<Table border = 0 cellpadding = 0 cellspacing = 0 id = "table">

<Tr>

<Td>

</Td>

<Td>

</Td>

<Td>

</Td>

<Td>

</Td>

<Td>

</Td>

</Tr>

</Table>

</Td>

<Td id = www_qpsh_com2 valign = top> </td>

</Tr> </table>

</Div>

This article is from the "IT" blog, please be sure to keep this source http://3795780.blog.51cto.com/3785780/1303320

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.