Skip to content

Commit

Permalink
Merge pull request #2525 from CCAFS/A2-311-Timeline-visual-change
Browse files Browse the repository at this point in the history
🐛 fix(Timeline): twice interval update solved with condition
  • Loading branch information
MetalPrime authored May 6, 2024
2 parents ae487df + cc5be18 commit 4f34b54
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions marlo-web/src/main/webapp/crp/js/home/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,13 @@ function moveScrollRight() {
element.style.scrollBehavior = "smooth"
element.scrollLeft += (containerSize);

let onlyActive = true;
setTimeout(() => {
getIntersectedActivities();
if(onlyActive){
getIntersectedActivities();
onlyActive = false;
}

}, 500);

}
Expand All @@ -196,8 +201,13 @@ function moveScrollLeft() {
element.style.scrollBehavior = "smooth"
element.scrollLeft -= (containerSize);

let onlyActive = true;
setTimeout(() => {
getIntersectedActivities();
if(onlyActive){
getIntersectedActivities();
onlyActive = false;
}

}, 500);
}

Expand Down Expand Up @@ -296,6 +306,8 @@ function getIntersectedActivities() {
return rectA.left - rectB.left;
});

console.log(activitiesIntersected.length);

activitiesIntersected.forEach(activity => {
if(activitiesIntersected.length === 1){
$(activity).parent().addClass("activityUnique");
Expand All @@ -312,7 +324,6 @@ function getIntersectedActivities() {

}
});
console.log(activitiesIntersected.length);

switch(activitiesIntersected.length){
case 1:
Expand All @@ -338,6 +349,7 @@ function getIntersectedActivities() {
case 6:
case 7:
case 8:
case 9:
if(document.documentElement.getBoundingClientRect().width > 1500){
timelineContainer.style.height = "31vh";
} else {
Expand All @@ -360,33 +372,16 @@ function getIntersectedActivities() {

},{
rootMargin: '0px',
threshold: 0.01,
threshold: 0.001,
});

let observerCalled = false;
const handleScroll = () => {
if (!observerCalled) {
observerCalled = true;
observer.disconnect();
window.requestAnimationFrame(() => {
observerCalled = false;
list_activities.forEach(activity => {
observer.observe(activity);
});
});
}
};

window.addEventListener('scroll', handleScroll);

list_activities.forEach(activity => {
observer.observe(activity);
});

setTimeout(() => {
observer.disconnect();
window.removeEventListener('scroll', handleScroll);
}, 155); // Adjust the time as per your scroll smooth time
}, 25); // Adjust the time as per your scroll smooth time

}

Expand Down

0 comments on commit 4f34b54

Please sign in to comment.