JS Object-oriented method: Picture uninterrupted left-scroll code

Source: Internet
Author: User

Article Introduction: the picture seamlessly scrolls to the left JavaScript code, this article is an example, the WEBJX netizen may change the picture address to own picture address to browse the test locally.

The picture seamlessly scrolls to the left JavaScript code, this article is an example, the WEBJX netizen may change the picture address to own picture address to browse the test locally.

<! 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=utf-8 "/>

<title> picture seamlessly scroll to the left JavaScript code-web teaching Network webjx.com</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" >

function Slide (obj,direction,speed) {

This.container=document.getelementbyid (obj);

This.content=this.container.getelementsbytagname ("ul") [0];

This.lis=this.content.getelementsbytagname ("Li");

This.imgs=this.content.getelementsbytagname ("img");

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

}

This.time=setinterval (function () {

that.content.style.left=that.content.offsetleft+that.speed+ "px";

if (that.content.offsetLeft <=-that.content.offsetwidth/2) {

That.content.style.left = "0px";

}else if (That.content.offsetLeft >=0) {

That.content.style.left =-that.content.offsetwidth/2 + "px";

}

},30)

for (Var i=0;i<this.imgs.length;i++) {


That.imgs[i].onmouseover = function () {

Clearinterval (That.time)

}

That.imgs[i].onmouseout=function () {

That.time=setinterval (function () {

that.content.style.left=that.content.offsetleft+that.speed+ "px";

if (that.content.offsetLeft <=-that.content.offsetwidth/2) {

That.content.style.left = "0px";

}else if (That.content.offsetLeft >=0) {

That.content.style.left =-that.content.offsetwidth/2 + "px";

}

},30)

}

}

}

</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.