wxs中requestAnimationFrame方法如何使用的?
wxs中requestAnimationFrame方法如何使用的? 为什么打印的timestamp是undefined 这个跟浏览器原生的window.requestAnimationFrame方法有哪些不一样 function startAnimation(event, ownerInstance) {
var instance = ownerInstance || event.instance;
var startTime = null;
var duration = 1000; // 动画持续时间1秒
var startPos = 0;
var endPos = 200;
console.log(111);
function animate(timestamp) {
console.log('timestamp', timestamp);
if (!startTime) startTime = timestamp;
var progress = Math.min((timestamp - startTime) / duration, 1);
var currentPos = startPos + (endPos - startPos) * progress;
instance.setStyle({
'transform': 'translateX(' + currentPos + 'px)'
});
if (progress < 1) {
instance.requestAnimationFrame(animate);
}
}
instance.requestAnimationFrame(animate);
}