@@ -5,8 +5,9 @@ let newsDirection = true
5
5
6
6
export function newsCardsScroll ( ) {
7
7
let currTop = newsCardContainerTop
8
+ let flag = true
8
9
9
- if ( true ) {
10
+ if ( flag ) {
10
11
let curr = 0
11
12
if ( newsDirection ) {
12
13
curr = newsCardsContainer . scrollTop + 1
@@ -15,11 +16,23 @@ export function newsCardsScroll() {
15
16
}
16
17
newsCardsContainer . scrollTop = curr
17
18
newsCardContainerTop = curr
19
+
20
+ if ( newsCardContainerTop == currTop ) {
21
+ newsDirection = ! newsDirection
22
+ }
23
+ } else {
24
+ return
18
25
}
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
+ // )
23
36
}
24
37
25
38
const publicationContainer = document . getElementById ( 'publication-cards' )
@@ -42,7 +55,10 @@ export function publicationCardsScroll() {
42
55
if ( publicationContainerTop == currTop ) {
43
56
publicationDirection = ! publicationDirection
44
57
}
45
- setTimeout ( publicationCardsScroll , 15 )
58
+ const timer = setTimeout ( publicationCardsScroll , 15 )
59
+ publicationContainer . addEventListener ( 'mouseenter' , ( ) => {
60
+ clearTimeout ( timer )
61
+ } )
46
62
}
47
63
48
64
// Scroll to top Button
0 commit comments