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.
This commit is contained in:
parent
0b5c85273d
commit
1abae9bd7a
1 changed files with 8 additions and 3 deletions
11
script.js
11
script.js
|
@ -213,10 +213,15 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
var sections = $('.section');
|
var sections = $('.section');
|
||||||
|
var found = false;
|
||||||
|
|
||||||
sections.each(function (index) {
|
sections.each(function (index) {
|
||||||
if ($(this).find('script[data-activity-id]').length > 0) {
|
if (!found && $(this).find('script[data-activity-id]').length > 0) {
|
||||||
// Hide all .section elements after this one
|
// Set found to true when the first matching section is found
|
||||||
sections.slice(index + 1).css('visibility', 'hidden');
|
found = true;
|
||||||
|
} else if (found) {
|
||||||
|
// Hide all .section elements after the found one
|
||||||
|
$(this).css('visibility', 'hidden');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue