Last active
May 4, 2022 01:40
-
-
Save kobitoDevelopment/7c74d4bb2b357bbb63d9a8130c3ce6c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p class="hoge" style="margin-top:1000px;">hoge</p> | |
<p class="hoge" style="margin-top:1000px;">hoge</p> | |
<p class="hoge" style="margin-top:1000px;">hoge</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const windowH = window.innerHeight; | |
window.addEventListener( | |
"scroll", | |
function () { | |
if (document.querySelector(".hoge") != null) { | |
const hoge = document.querySelectorAll(".hoge"); | |
hoge.forEach(function (elem, index) { | |
const rect = elem.getBoundingClientRect(); | |
const scrollTop = window.pageYOffset || document.documentElement.scrollTop; | |
const hogeTop = rect.top + scrollTop; | |
if (scrollTop > hogeTop - windowH) { | |
//スクロールトリガー通過後の処理を記述 | |
elem.style.transition = "1s"; | |
elem.style.color = "red"; | |
elem.classList.remove("hoge"); | |
} | |
}); | |
} | |
}, | |
{ passive: true } | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment