JS Seamless Scrolling (general method + Object-oriented method) _javascript skills

Source: Internet
Author: User
Tags setinterval
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; CHARSET=GBK "/>
<title>js Seamless Scrolling (general method + Object-oriented method) </title>
<style type= "Text/css" >
. clearfix:after {content: "."; display:block; height:0; visibility:hidden; clear:both;}
. clearfix {*zoom:1}
Body{background:gray;}
#wrap {width:810px; height:160px;
BORDER:1PX solid black;
position:relative;
left:50%;
top:50%;
margin-left:-410px;
margin-top:200px;
Background: #fff;
Overflow:hidden;}
#wrap ul{margin:0px;
padding:0px;
Position:absolute;
top:0px;
left:0px;}
#wrap ul li{List-style:none; float:left;margin:5px 10px;width:265px;}
#wrap ul Li img{border:1px black solid; padding:10px;}
</style>
<!--script type= "Text/javascript" >
Window.onload=function () {//General method
var Wrap=document.getelementbyid ("Wrap");
var wrap_ul=wrap.getelementsbytagname ("ul") [0];
var wrap_li=wrap.getelementsbytagname ("Li");
wrap_ul.innerhtml+=wrap_ul.innerhtml;
Wrap_ul.style.width= (wrap_li[0].offsetwidth+20) *wrap_li.length+ "px";
Autoscroll=setinterval (scroll,100);
function Scroll () {
wrap_ul.style.left=wrap_ul.offsetleft-3+ "px"; This is because IE is different to offsetleft, so IE must reduce the number greater than or equal to 3
if (WRAP_UL.OFFSETLEFT&LT;=-WRAP_UL.OFFSETWIDTH/2) {
wrap_ul.style.left= "0px";
}else if (wrap_ul.offsetleft>=0) {
wrap_ul.style.left=-wrap_ul.offsetwidth/2+ "px";
}
}
Wrap.onmouseover=function () {
Clearinterval (AutoScroll);
}
Wrap.onmouseout=function () {
Autoscroll=setinterval (scroll,100);
}
}
</script-->
<script type= "Text/javascript" >
function Slide (obj,direction,speed) {//object-oriented method, free to control the direction, speed=>3 ie can
This.container=document.getelementbyid (obj);
This.content=this.container.getelementsbytagname ("ul") [0];
This.lis=this.content.getelementsbytagname ("Li");
this.content.innerhtml+=this.content.innerhtml;
This.content.style.width= (this.lis[0].offsetwidth+20) *this.lis.length+ "px";
var that=this
if (direction== "left") {
This.speed=-speed
}else if (direction== "right") {
This.speed=speed
}
Slide.prototype.scroll=function () {
this.content.style.left=this.content.offsetleft+this.speed+ "px";
if (this.content.offsetLeft <=-this.content.offsetwidth/2) {
This.content.style.left = "0px";
}else if (This.content.offsetLeft >=0) {
This.content.style.left =-this.content.offsetwidth/2 + "px";
}
}
This.time=setinterval (function () {that.scroll ()},100);
This.container.onmouseover=function () {
Clearinterval (That.time);
}
This.container.onmouseout=function () {
That.time=setinterval (function () {that.scroll ()},100);
}
}
</script>
<script type= "Text/javascript" >
Window.onload=function () {New Slide ("Wrap", "left", 5)}
</script>


<body>
<div id= "Wrap" >
<ul class= "Clearfix" >
<li><a href= "#" ></a></li>
<li><a href= "#" ></a></li>
<li><a href= "#" ></a></li>
<li><a href= "#" ></a></li>
<li><a href= "#" ></a></li>
</ul>
</div>
</body>

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.