The implementation of seamless scrolling on web pages

Source: Internet
Author: User

Seamless scrolling:

1. Implementation principle: In a fixed-size div inside (Div needs to set Overfloow:hidden overflow part hidden!) Change the value of the offsetleft or offsetright of the picture! To achieve picture movement (need to add position:absolute to the picture)!

2. Change the value of left or right, you need to use the timer setinterval (called function, the time of the call)

3. When the left or right of the picture is greater than the length of the picture itself, it will appear blank! The solution is simply to copy one itself! When left or RIGHR is greater than or equal to the normal time, leave or right is re-assigned to a value of 0.

The code is as follows:

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<style type= "Text/css" >
#div1 {

width:100px;
height:100px;
Overflow:hidden;
}
li{
Float:left;
}
ul{
Position:absolute;
left:0px;
top:0px;
}
</style>
<body>

<div id= "Div1" >
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</div>

</body>
<script type= "Text/javascript" >
var Oul=document.getelementbyid ("ul");
var s=5;//defined Speed
var fuzhi=oul.innerhtml+oul.innerhtml;
Oul.innerhtml=fuzhi;
Div1.onclick=function () {

Clearinterval (t);
T=setinterval (timer,30);
};
function timer () {
oul.style.left=oul.offsetleft-sudu+ "px";
            if (oul.offsetleft<=-300) {
oul.style.left=0;
        }


</script>

The implementation of seamless scrolling on web pages

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.