English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
requestAnimationFrame()方法告诉浏览器您希望执行动画,并请求浏览器在下一次重新绘制之前调用指定的函数来更新动画。
该方法将回调作为要在重绘之前调用的参数。
window.requestAnimationFrame(callback)
var start = null; var element = document.getElementById('anim'); function step(timestamp) { if (!start) start = timestamp; var progress = timestamp - start; element.style.transform = 'translateX(' + Math.min(progress / 10, 400) + 'px)'; if (progress < 20000) {}} window.requestAnimationFrame(step); } } window.requestAnimationFrame(step);Vérifiez voir‹/›
Les nombres dans le tableau indiquent la première version du navigateur qui prend en charge pleinement la méthode requestAnimationFrame() :
Méthode | |||||
requestAnimationFrame() | 24 | 23 | 15 | 6.1 | 10 |
Paramètres | Description |
---|---|
Callback | Fonction appelée lorsque l'animation doit être mise à jour pour le redessin suivant |
Valeur de retour : | Un nombre entier long (ID de requête), utilisé pour identifier de manière unique une entrée dans la liste de rappels |
---|
Tutoriel CSS :Animation CSS
Référence CSS :Propriétés de l'animation CSS
Référence CSS :Animation CSS-Propriété délai de l'animation CSS
Référence CSS :Propriété direction de l'animation CSS
Référence CSS :Propriété durée de l'animation CSS
Référence CSS :Animation CSS-Fill-Propriété mode
Référence CSS :Animation CSS-Iteration-Propriété count
Référence CSS :Animation CSS-Propriété name
Référence CSS :Animation CSS-Play-Propriété state
Référence CSS :Animation CSS-Timing-Propriété function