Javascript automatically plays slide effect code

Source: Internet
Author: User
The code is as follows Copy Code

<! 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> Auto Playback-slide buffer effect </title>
<style>
body,div,ul,li{margin:0;padding:0;}
Ul{list-style-type:none;}
Body{background: #000; text-align:center;font:12px/20px Arial;
#box {position:relative;width:492px;height:172px;background: #fff; border-radius:5px;border:8px solid #fff; margin : 10px Auto;cursor:pointer;}
#box. List{position:relative;width:490px;height:170px;overflow:hidden;}
#box. List ul{position:absolute;top:0;left:0;}
#box. List Li{width:490px;height:170px;overflow:hidden;}
#box. count{position:absolute;right:0;bottom:5px;}
#box. Count Li{color: #fff; float:left;width:20px;height:20px;cursor:pointer;margin-right:5px;overflow:hidden; Background: #F90; Opacity:0.7;filter:alpha (opacity=70); border-radius:20px;}
#box. Count Li.current{color: #fff; Opacity:1;filter:alpha (opacity=100); Font-weight:700;background: #f60;}
#tmp {Width:100px;height:100px;background:red;position:absolute;}
</style>
<script type= "Text/javascript" >
Window.onload = function ()
{
var Obox = document.getElementById ("box");
var olist = obox.getelementsbytagname ("ul") [0];
var aimg = obox.getelementsbytagname ("img");
var timer = Playtimer = null;
var index = i = 0;
var bOrder = true;
var aTmp = [];
var abtn = null;

Generate a number button
for (i = 0; i < aimg.length i++) Atmp.push ("<li>" + (i + 1) + "</li>");

inserting elements
var ocount = document.createelement ("ul");
Ocount.classname = "Count";
ocount.innerhtml = Atmp.join ("");
Obox.appendchild (Ocount);
ABTN = Obox.getelementsbytagname ("ul") [1].getelementsbytagname ("Li");

Initialization status
Cutover ();

button click to toggle
for (i = 0; i < abtn.length; i++)
{
Abtn[i].index = i;
Abtn[i].onmouseover = function ()
{
index = This.index;
Cutover ()
}
}

function cutover ()
{
for (i = 0; i < abtn.length i++) Abtn[i].classname = "";
Abtn[index].classname = "current";
Startmove (-(Index * aimg[0].offsetheight))
}

function Next ()
{
BOrder? index++: index--;
Index <= 0 && (index = 0, BOrder = true);
Index >= abtn.length-1 && (index = abtn.length-1, BOrder = False)
Cutover ()
}

Playtimer = SetInterval (Next, 3000);

Mouse move into the display area to stop AutoPlay
Obox.onmouseover = function ()
{
Clearinterval (Playtimer)
};

The mouse leaves the display area to start playing automatically
Obox.onmouseout = function ()
{
Playtimer = SetInterval (Next, 3000)
};
function Startmove (itarget)
{
Clearinterval (timer);
Timer = setinterval (function ()
{
Domove (ITarget)
}, 30)
}
function Domove (itarget)
{
var ispeed = (itarget-olist.offsettop)/10;
Ispeed = ispeed > 0? Math.ceil (ispeed): Math.floor (Ispeed);
Olist.offsettop = = ITarget? Clearinterval (timer): OList.style.top = olist.offsettop + ispeed + "px"
}
};
</script>
<body>
<div id= "box" >
<div class= "List" >
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</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.