Skip to content

Instantly share code, notes, and snippets.

@kobitoDevelopment
Last active May 4, 2022 01:40
Show Gist options
  • Save kobitoDevelopment/7c74d4bb2b357bbb63d9a8130c3ce6c5 to your computer and use it in GitHub Desktop.
Save kobitoDevelopment/7c74d4bb2b357bbb63d9a8130c3ce6c5 to your computer and use it in GitHub Desktop.
<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>
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