javascript - Change class on scroll -
i've been looking around online can't find problem im having (at least not limited js level)
i'm trying achieve effect change .class css when scrolls or swipes down page.
eg. <a>
tages blue, if user scrolls 20px down or 50px down... <a
> tags turn green , id scrolling stops. tags turn blue
you'll need bind scroll event, using window.onscroll: https://developer.mozilla.org/en-us/docs/web/api/window.onscroll function changes class on element you're interested in.
// event "onscroll" on window object, we're binding , passing // anonymous function function executed when event triggered window.onscroll = function (event) { // here (inside anonymous function that's being passed in), add class // "my-class" document body. document.body.classlist.add("my-class"); }
note: should give enough information solve problem yourself, don't want solve - in example, function called every time window scrolled (so you'll want add sort of check/limit), , classlist doesn't work in older browsers.
Comments
Post a Comment