Javascript automatic playback code

Source: Internet
Author: User

[Html]
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<Html>
<Head>
<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 entry of the array is long, and other items can be customized.
Data = [["3", "a"], ["2", "B"], ["3", "c"], ["2 ", "d"], ["1", ""];
 
$ (Document). ready (function (){
// Set the trigger event
AutoPlay. run = function (obj, num ){
Back (obj, num );
};
AutoPlay ();
});

Function back (obj, num ){
$ ("# Div_show" cmd.html (obj [num] [1]);
}

Function autoPlay (){
// Initialize counting Parameters
If (autoPlay. num = undefined)
AutoPlay. num = 0;
// Initialization time point
If (autoPlay. timepoint = undefined)
AutoPlay. timepoint = new Date (). getTime ();
If (autoPlay. num <data. length ){
// Function handle, data array, current subscript of autoPlay. num
AutoPlay. run (data, autoPlay. num );
// Play the Array Based on the element length
If (new Date (). getTime ()> autoPlay. timepoint ){
// Determine whether it is the first execution
If (autoPlay. first = undefined)
AutoPlay. first = true;
Else
AutoPlay. num ++;
// Set the next playback time point
AutoPlay. timepoint + = (data [autoPlay. num] [0] * 1000 );
}
SetTimeout ("autoPlay ()", 500 );
}
}

$. Extend ({autoPlay: function (){
Var defaults = {inteval: 500 };
}});
 
</Script>
</Head>
<Body>
<Div id = "div_show"> </div>
</Body>
</Html>

Defines the playback time and 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.