JS automatic playback of instance code _javascript skills

Source: Internet
Author: User

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=utf-8 "/>
<title>auto play</title>
<script type= "Text/javascript" src= ". /jquery-1.8.0.min.js "/></script>
<script type= "Text/javascript" >
The first item of the array is long and other items can be customized
data = [[[3], "a"],["2", "B"],["3", "C"],["2", "D"],["1", ""]];

$ (document). Ready (function () {
Setting Trigger Events
Autoplay.run = function (obj,num) {
Back (Obj,num);
};
AutoPlay ();
});

function back (obj,num) {
$ ("#div_show"). html (obj[num][1]);
}

function AutoPlay () {
Initialization count parameters
if (Autoplay.num ==undefined)
Autoplay.num = 0;
Initialize point of Time
if (Autoplay.timepoint ==undefined)
Autoplay.timepoint = new Date (). GetTime ();
if (autoplay.num<data.length) {
function handle, data array, autoplay.num current subscript
Autoplay.run (Data,autoplay.num);
Play array by element time length
if (new Date (). GetTime () >autoplay.timepoint) {
Determine whether the first execution
if (autoplay.first==undefined)
Autoplay.first = true;
Else
autoplay.num++;
Set the time point for the next playback
Autoplay.timepoint + = (data[autoplay.num][0]*1000);
}
SetTimeout ("AutoPlay ()", 500);
}
}

$.extend ({autoplay:function () {
var defaults = {inteval:500};
}});

</script>
<body>
<div id= "Div_show" ></div>
</body>


Define playback time, you can define events

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.