From 1abae9bd7af5d4e89b089c5e6028fb5a6e116ab5 Mon Sep 17 00:00:00 2001 From: Kumi Date: Mon, 23 Sep 2024 09:22:41 +0200 Subject: [PATCH] fix(scripts): avoid redundant visibility settings in loop Refactored section visibility handling to prevent unnecessary CSS updates by ensuring that only sections after the first matched section are hidden. This improves performance and prevents potential flickering issues. --- script.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/script.js b/script.js index 3944ec6..2a5c59b 100644 --- a/script.js +++ b/script.js @@ -213,10 +213,15 @@ }); var sections = $('.section'); + var found = false; + sections.each(function (index) { - if ($(this).find('script[data-activity-id]').length > 0) { - // Hide all .section elements after this one - sections.slice(index + 1).css('visibility', 'hidden'); + if (!found && $(this).find('script[data-activity-id]').length > 0) { + // Set found to true when the first matching section is found + found = true; + } else if (found) { + // Hide all .section elements after the found one + $(this).css('visibility', 'hidden'); } }); })