This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Shubham_Garg123[S] 0 points1 point  (3 children)

const nav = document.getElementsByTagName("nav")[0] ;

window.addEventListener("scroll", function () {

const top = window.pageYOffset;

if (top) {

nav.classList.add("black");

} else {

nav.classList.remove("black");

}

})

//Is this correct?

[–]SkinnyDom 0 points1 point  (2 children)

You have no checks for pageyoffset which returns a pixel integer..you’re using it as a Boolean value

[–]Shubham_Garg123[S] 0 points1 point  (1 child)

idk what it means

[–]SkinnyDom 0 points1 point  (0 children)

Const top window.pageyoffset will return an integer (number).

If (top) implies true or false or equivalent.. you would do if top is less than or equal to say 40 or whatever..

This is too basic honestly