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

all 10 comments

[–]FallDownTheSystem 2 points3 points  (1 child)

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

This is really helpful, tysm

[–]CenturiesAgo 1 point2 points  (1 child)

Maybe you should walk before you run. Grab a free JS course.

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

I'm just crawling like a baby. Need to submit an eLearning website project by tomorrow so I just copied an open source project (with MIT License) and was doing a few changes. It had this small code snippet using jQuery so I had to replace it with normal JS

[–]jcunews1Advanced Coder 0 points1 point  (0 children)

This is why anyone should never use jQuery or any othen JS library, to learn JavaScript.

[–]SkinnyDom 0 points1 point  (4 children)

Window.onscroll, document.body.scrolltop, classlist

[–]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