From f53abaf13b2b76b7c9385fe3630dd737a50bad78 Mon Sep 17 00:00:00 2001 From: Roman Pyrih Date: Thu, 17 Apr 2025 12:38:19 +0200 Subject: [PATCH] REFactor: encapsulate scroll check logic into a function --- wp-content/themes/restly-child/assets/js/custom.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/wp-content/themes/restly-child/assets/js/custom.js b/wp-content/themes/restly-child/assets/js/custom.js index 0fdd1acc..a30cfba5 100644 --- a/wp-content/themes/restly-child/assets/js/custom.js +++ b/wp-content/themes/restly-child/assets/js/custom.js @@ -39,13 +39,17 @@ jQuery(function($) { }) jQuery(function($) { - $(window).scroll(function() { - if ($(this).scrollTop() >= 100) { + function checkScroll() { + if ($(window).scrollTop() >= 100) { $('header#masthead').addClass('fixed'); } else { $('header#masthead').removeClass('fixed'); } - }); + } + + $(window).scroll(checkScroll); + + checkScroll(); }); jQuery(document).ready(function ($) {