What is Requestanimationframe?
In the browser animation program, we usually use a timer to cycle every few milliseconds to move the object once, to make it move. Now that the good news is that the browser developers have provided this requestanimationframe () API function for animation, you can use it on a DOM style change or canvas animation or WEBGL.
Example
<! DOCTYPE html>
<meta name= "viewport" content= "Width=device-width,user-scalable=no, initial-scale=1, maximum-scale=1, User-scalable=0 "/>
<meta name= "apple-mobile-web-app-capable" content= "yes"/>
<meta name= "Apple-mobile-web-app-status-bar-style" content= "Black-translucent"/>
<title> How to use Requestanimationframe to create an animation </title>
<body>
<div id= "test" style= "Width:1px;height:17px;background: #0f0;" >0%</div>
<script>
Http://paulirish.com/2011/requestanimationframe-for-smart-animating
http://www.webhek.com/requestanimationframe/
Http://www.cnblogs.com/Wayou/p/requestAnimationFrame.html
Shim layer with settimeout fallback
Window.requestanimframe = (function () {
return Window.requestanimationframe | |
Window.webkitrequestanimationframe | |
Window.mozrequestanimationframe | |
Window.orequestanimationframe | |
Window.msrequestanimationframe | |
Function (callback) {
Window.settimeout (callback, 1000/60);
};
})();
var feng={
progress:0,
Ele:null,
Test:function () {
feng.progress++;
Feng.ele=document.getelementbyid ("test");
Feng.ele.style.width = feng.progress + "%";
feng.ele.innerhtml=feng.progress + "%";
if (feng.progress<100) {
Requestanimframe (feng.test);
}
},
Init:function () {
Feng.test ();
}
}
Window.addeventlistener (' Load ', Feng.init, false);
</script>
</body>