Created
August 3, 2021 12:10
-
-
Save ankedsgn/82765608773346cc5004dbaa7a53ab4a to your computer and use it in GitHub Desktop.
Add class when page is scrolled farther dan Xpx down (drupal jquery)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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