Skip to content

Commit ed493e5

Browse files
Merge pull request wdmc-nitj#188 from wdmc-nitj/clubs-merging
Stop scroll on hover
2 parents 6ca516f + d11ed99 commit ed493e5

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

js/utils/app/scrollUtils.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ let newsDirection = true
55

66
export function newsCardsScroll() {
77
let currTop = newsCardContainerTop
8+
let flag = true
89

9-
if (true) {
10+
if (flag) {
1011
let curr = 0
1112
if (newsDirection) {
1213
curr = newsCardsContainer.scrollTop + 1
@@ -15,11 +16,23 @@ export function newsCardsScroll() {
1516
}
1617
newsCardsContainer.scrollTop = curr
1718
newsCardContainerTop = curr
19+
20+
if (newsCardContainerTop == currTop) {
21+
newsDirection = !newsDirection
22+
}
23+
} else {
24+
return
1825
}
19-
if (newsCardContainerTop == currTop) {
20-
newsDirection = !newsDirection
21-
}
22-
setTimeout(newsCardsScroll, 15)
26+
const newsTimeout = setTimeout(newsCardsScroll, 15)
27+
// stop the scroll while the mouse is in the div element and restart it when the mouse leaves the div element
28+
// avoid the function to be called multiple times
29+
newsCardsContainer.addEventListener('mouseenter', () => {
30+
clearTimeout(newsTimeout)
31+
})
32+
// newsCardsContainer.addEventListener('mouseleave', () => {
33+
// newsCardsScroll()
34+
// }
35+
// )
2336
}
2437

2538
const publicationContainer = document.getElementById('publication-cards')
@@ -42,7 +55,10 @@ export function publicationCardsScroll() {
4255
if (publicationContainerTop == currTop) {
4356
publicationDirection = !publicationDirection
4457
}
45-
setTimeout(publicationCardsScroll, 15)
58+
const timer = setTimeout(publicationCardsScroll, 15)
59+
publicationContainer.addEventListener('mouseenter', () => {
60+
clearTimeout(timer)
61+
})
4662
}
4763

4864
// Scroll to top Button

0 commit comments

Comments
 (0)