我使用這個函數來設置一些元素的轉換屬性,但是在firefox中動畫並不那麼流暢,而且當窗口大小更大時(在任何瀏覽器中),它都不那麼流暢。我讀了很多事情的博客上說,我可以使用requestAnimationFrame更平滑的動畫,但我不明白我如何在我的函數內部實現它。可以有人解釋我如何在我的函數中使用它嗎?using requestAnimationFrame
function sectionMovement(delay,section) {
setTimeout(function() {
var val = ((v.sectionIndex + 1) > v.leavingSection) ?
val = 100 :
val = 0;
document.getElementById("sec_"+section+"").style.transform = "translateY(-"+val+"%)"
}, delay);
};
你是怎麼調用這個函數的? –
for循環內部 - > sectionMovement(i * 750,((v.sectionIndex + 1)> v.leavingSection)?(SIV + 1):SIV) – Matija
有你的答案。 https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame –