簡體   English   中英

當元素到達視口的一半時,我可以觸發 animation 嗎?

[英]Can I trigger an animation when an element reaches half way in the viewport?

(JavaScript)我可以看到當元素進入和離開視口時使用 IntersectionObserver 觸發 animation 是可能的 - 但是當元素到達視口的一半時有沒有辦法觸發 animation?

你可以使用類似的東西

new IntersectionObserver(yourAnimation, {rootMargin: "0px 0px -50% 0px"})

當你的元素進入視口的上半部分時,它就會相交。 基本上將其高度的一半的負邊距添加到根的底部邊緣(這里是視口)

您可以使用

if(elment.offsetLeft==window.offsetWidth) {startAnimation()}
// or element.offsetTop and window.offsetHeight
//you should write the startAnimation function, it not a built-in function

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM