Skip to content

Commit cdf446a

Browse files
committed
Remove auto-scrolling in validators/accordions
Stop automatic page jumps caused by various validation and accordion helpers. Removed animate-scroll calls from validation flows (assets/js/functions/validation.js and assets/js/luxuryCar.js) and from openNextAccordion (assets/js/components/productPage.js and assets/js/luxuryCar.js). Instead, productPage.priplatky now explicitly scrolls to the next step after opening it (delayed 600ms) so scrolling is applied only where intended. This prevents unexpected scrolling when marking errors or opening accordions and centralizes scroll behavior.
1 parent 4f9b8ab commit cdf446a

File tree

3 files changed

+6
-61
lines changed

3 files changed

+6
-61
lines changed

assets/js/components/productPage.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,10 @@ function priplatky(setupData, texts) {
471471
if (currentIndex < allWraps.length - 1) {
472472
const nextWrap = allWraps.eq(currentIndex + 1);
473473

474-
// Nechej současný krok otevřený, otevři a scrolluj na další
475474
openNextAccordion(nextWrap);
475+
setTimeout(() => {
476+
$("html, body").animate({ scrollTop: nextWrap.offset().top - 80 }, 400);
477+
}, 600);
476478

477479
console.log("Přechod k dalšímu kroku:", nextWrap.find(".variant.name, h5").first().text() || "Unnamed");
478480
} else {
@@ -678,13 +680,9 @@ function priplatky(setupData, texts) {
678680
}
679681
}
680682

681-
// Otevře akordeon a scrolluje na něj — předchozí kroky zůstávají otevřené
683+
// Otevře akordeon bez scrollování
682684
function openNextAccordion($next) {
683685
$next.addClass("active");
684-
// Čekáme na dokončení CSS animací předchozích akordeonů, pak teprve počítáme offset
685-
setTimeout(() => {
686-
$("html, body").animate({ scrollTop: $next.offset().top - 80 }, 400);
687-
}, 600);
688686
}
689687

690688
// Single event listener for .upsale-button

assets/js/functions/validation.js

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,9 @@ export function validation(texts) {
1111
// Find highest errorToCart element and scroll to it
1212
const $errorElements = $(".errorToCart");
1313
if ($errorElements.length) {
14-
const topElement = $errorElements.toArray().reduce((prev, curr) => {
14+
$errorElements.toArray().reduce((prev, curr) => {
1515
return $(prev).offset().top < $(curr).offset().top ? prev : curr;
1616
});
17-
18-
$("html, body").animate(
19-
{
20-
scrollTop: $(topElement).offset().top - 300,
21-
},
22-
500
23-
);
2417
}
2518
});
2619

@@ -62,16 +55,6 @@ function upsaleValidation(e) {
6255
$(".upsale-buttons").each(function () {
6356
if (!$(this).find(".active").length) {
6457
$(this).addClass("errorToCart").addClass("active");
65-
const $errorElement = $(".errorToCart:eq(0)");
66-
console.log($errorElement.length);
67-
if ($errorElement.length) {
68-
$("html, body").animate(
69-
{
70-
scrollTop: $errorElement.offset().top - 100,
71-
},
72-
500
73-
);
74-
}
7558
setTimeout(() => {
7659
$(this).removeClass("errorToCart");
7760
}, 2000);
@@ -125,16 +108,6 @@ function boxValidation(e) {
125108
});
126109

127110
if (!allWrapsHaveActive) {
128-
const $errorElement = $(".errorToCart:eq(0)");
129-
if ($errorElement.length) {
130-
$("html, body").animate(
131-
{
132-
scrollTop: $errorElement.offset().top - 100,
133-
},
134-
500
135-
);
136-
}
137-
138111
setTimeout(() => {
139112
$(".parameter-wrap").removeClass("errorToCart");
140113
}, 2000);
@@ -230,15 +203,6 @@ function optionTest() {
230203
}
231204
});
232205

233-
if (firstErrorElement) {
234-
$("html, body").animate(
235-
{
236-
scrollTop: firstErrorElement.offset().top - 100,
237-
},
238-
500
239-
);
240-
}
241-
242206
return allSelected;
243207
}
244208
function createpopup(texts) {

assets/js/luxuryCar.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,9 +1368,6 @@ function priplatky(setupData2, texts) {
13681368
}
13691369
function openNextAccordion($next) {
13701370
$next.addClass("active");
1371-
setTimeout(() => {
1372-
$("html, body").animate({ scrollTop: $next.offset().top - 80 }, 400);
1373-
}, 600);
13741371
}
13751372
$(document).on("click", ".upsale-button", function(e) {
13761373
updateUpsale(this, e);
@@ -2347,15 +2344,9 @@ function validation(texts) {
23472344
errorToCart(e, texts);
23482345
const $errorElements = $(".errorToCart");
23492346
if ($errorElements.length) {
2350-
const topElement = $errorElements.toArray().reduce((prev, curr) => {
2347+
$errorElements.toArray().reduce((prev, curr) => {
23512348
return $(prev).offset().top < $(curr).offset().top ? prev : curr;
23522349
});
2353-
$("html, body").animate(
2354-
{
2355-
scrollTop: $(topElement).offset().top - 300
2356-
},
2357-
500
2358-
);
23592350
}
23602351
});
23612352
$(document).on("click", ".close-btn.return", function() {
@@ -2434,14 +2425,6 @@ function optionTest() {
24342425
allSelected = false;
24352426
}
24362427
});
2437-
if (firstErrorElement) {
2438-
$("html, body").animate(
2439-
{
2440-
scrollTop: firstErrorElement.offset().top - 100
2441-
},
2442-
500
2443-
);
2444-
}
24452428
return allSelected;
24462429
}
24472430
function createpopup2(texts) {

0 commit comments

Comments
 (0)