Novo JavaScript para Rotations
Criado um arquivo JavaScript com código para realizar o scroll entre os cards de Movimentações em aberto assim como proporcionar uma animação fluida para o processo.
This commit is contained in:
1 parent
7e722c4294
commit
acd8225c3d
1 file changed
+39
@@ -0,0 +1,39 @@
|
|||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
const container = document.querySelector(".open-rotations-container");
|
||||||
|
|
||||||
|
if (!container) return;
|
||||||
|
|
||||||
|
let targetScroll = container.scrollLeft;
|
||||||
|
let currentScroll = container.scrollLeft;
|
||||||
|
let isAnimating = false;
|
||||||
|
|
||||||
|
container.addEventListener("wheel", (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const maxScroll =
|
||||||
|
container.scrollWidth - container.clientWidth;
|
||||||
|
|
||||||
|
targetScroll += event.deltaY;
|
||||||
|
|
||||||
|
// Prevent ghost scrolling
|
||||||
|
targetScroll = Math.max(0, Math.min(targetScroll, maxScroll));
|
||||||
|
|
||||||
|
if (!isAnimating) {
|
||||||
|
isAnimating = true;
|
||||||
|
animateScroll();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function animateScroll() {
|
||||||
|
currentScroll += (targetScroll - currentScroll) * 0.15;
|
||||||
|
|
||||||
|
container.scrollLeft = currentScroll;
|
||||||
|
|
||||||
|
if (Math.abs(targetScroll - currentScroll) > 0.5) {
|
||||||
|
requestAnimationFrame(animateScroll);
|
||||||
|
} else {
|
||||||
|
currentScroll = targetScroll;
|
||||||
|
isAnimating = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in new issue
Block a user