Skip to content

Instantly share code, notes, and snippets.

@ankedsgn
Created August 3, 2021 12:10
Show Gist options
  • Save ankedsgn/82765608773346cc5004dbaa7a53ab4a to your computer and use it in GitHub Desktop.
Save ankedsgn/82765608773346cc5004dbaa7a53ab4a to your computer and use it in GitHub Desktop.
Add class when page is scrolled farther dan Xpx down (drupal jquery)
(function ($, Drupal) {
$(window).on('scroll', function () {;
scrollingSwitch();
// console.log('scrolling scrolling scrolling');
});
function scrollingSwitch() {
var html = $('html');
var body = $('body');
var width = $(window).width();
var breakMobilemenu = 1140;
if (width >= breakMobilemenu) {
//desktop
if ((html.scrollTop() > 40 || body.scrollTop() > 40)) {
body.addClass('is-scrolled');
// console.log('html scrolltop:' + html.scrollTop());
} else {
body.removeClass('is-scrolled');
}
} else {
//mobile
if ((html.scrollTop() > 32 || body.scrollTop() > 32)) {
body.addClass('is-scrolled');
// console.log('html scrolltop:' + html.scrollTop());
} else {
body.removeClass('is-scrolled');
}
}
}
})(jQuery, Drupal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment