复制代码 代码如下:
<!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="/UploadFiles/2021-04-02/jquery-1.8.0.min.js"><script type="text/javascript">
    //数组的第一项为时长,其他项可自定义
    data = [["3","a"],["2","b"],["3","c"],["2","d"],["1",""]];

    $(document).ready(function(){
        //设置触发事件
        autoPlay.run = function(obj,num){
            back(obj,num);
        };
        autoPlay();
    });

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

    function autoPlay(){
        //初始化计数参数
        if(autoPlay.num ==undefined)
            autoPlay.num = 0;
        //初始化时间点
        if(autoPlay.timepoint ==undefined)
            autoPlay.timepoint = new Date().getTime();
        if(autoPlay.num<data.length){
            //函数句柄,data 数组,autoPlay.num当前下标
            autoPlay.run(data,autoPlay.num);
            //按照元素时间长度播放数组
            if(new Date().getTime()>autoPlay.timepoint){
                //判断是否为第一次执行
                if(autoPlay.first==undefined)
                    autoPlay.first = true;
                else
                    autoPlay.num++;
                //设置下一次播放的时间点
                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>


定义播放时间,可以定义事件

标签:
js,自动播放

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“js 自动播放的实例代码”

暂无“js 自动播放的实例代码”评论...