jQuery(function($){ var $header = $('.site-header'); if (!$header.length) return; var scrollClass = 'scrolled'; function getThreshold() { var w = $(window).width(); if (w <= 767) return 30; if (w <= 1024) return 60; return 100; } var threshold = getThreshold(); function checkScroll() { if ($(window).scrollTop() > threshold) $header.addClass(scrollClass); else $header.removeClass(scrollClass); } var resizeTimer; $(window).on('resize', function(){ clearTimeout(resizeTimer); resizeTimer = setTimeout(function(){ threshold = getThreshold(); checkScroll(); }, 150); }); $(window).on('scroll', checkScroll); checkScroll(); });
Aller au contenu