首页 > 其他 > 详细

简单的requestAnimationFrame动画

时间:2018-04-22 11:33:31      阅读:142      评论:0      收藏:0      [点我收藏+]

html部分

<div id="test" style="width:1px;height:17px;background:#0f0;">0%</div>
    <input type="button" value="Run" id="run"/>
    <script>
        window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
            var start = null;
            var ele = document.getElementById("test");
            var progress = 0;
            function step(timestamp) {
                progress += 1;
                ele.style.width = progress + "%";
                ele.innerHTML=progress + "%";
                if (progress < 100) {
                    setTimeout(function(){
                        requestAnimationFrame(step);
                    },50);
                    
                }
            }
            requestAnimationFrame(step);
            document.getElementById("run").addEventListener("click", function() {
                ele.style.width = "1px";
                progress = 0;
                requestAnimationFrame(step);//调用方法
            }, false);
    </script>

技术分享图片

简单的requestAnimationFrame动画

原文:https://www.cnblogs.com/aSnow/p/8906012.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!