@@ -47,10 +47,7 @@ export class SliderComponent implements AfterViewInit, OnDestroy {
47
47
this . slidesNumber = this . slides . length ;
48
48
this . timeBySlide = ( ! this . option . timeBySlide || ( this . option . timeBySlide < 2000 ) ) ? 5000 : this . option . timeBySlide ;
49
49
this . sliderContainerElement = this . sliderSection . nativeElement as HTMLElement ;
50
- this . movementInterval = window . setInterval ( ( ) => {
51
- const newPos = ( this . currentSlidePos === this . slidesNumber ) ? 1 : this . currentSlidePos + 1 ;
52
- this . setSlideWidthAnimation ( newPos ) ;
53
- } , this . timeBySlide ) ;
50
+ this . createSliderInterval ( ) ;
54
51
}
55
52
56
53
ngOnDestroy ( ) : void {
@@ -86,6 +83,7 @@ export class SliderComponent implements AfterViewInit, OnDestroy {
86
83
bulletSetSlide ( slideEnd : number ) {
87
84
if ( ! this . isOnAnimation ) {
88
85
this . setSlideWidthAnimation ( slideEnd ) ;
86
+ this . createSliderInterval ( ) ;
89
87
}
90
88
}
91
89
@@ -103,6 +101,7 @@ export class SliderComponent implements AfterViewInit, OnDestroy {
103
101
this . isDragEvent = true ;
104
102
this . isDragging = true ;
105
103
this . posSlider . posInitX = e . clientX ;
104
+ clearInterval ( this . movementInterval ) ;
106
105
}
107
106
108
107
@HostListener ( 'mousemove' , [ '$event' ] ) mouseMove ( e : MouseEvent ) {
@@ -124,6 +123,7 @@ export class SliderComponent implements AfterViewInit, OnDestroy {
124
123
this . isDragging = false ;
125
124
this . posSlider . posEndX = e . clientX ;
126
125
this . move ( ) ;
126
+ this . createSliderInterval ( ) ;
127
127
}
128
128
129
129
@@ -137,6 +137,7 @@ export class SliderComponent implements AfterViewInit, OnDestroy {
137
137
this . isDragging = true ;
138
138
this . posSlider . posInitX = e . touches [ 0 ] . clientX ;
139
139
this . posSlider . scrollInit = this . sliderContainerElement . scrollLeft ;
140
+ clearInterval ( this . movementInterval ) ;
140
141
}
141
142
142
143
@HostListener ( 'touchmove' , [ '$event' ] ) onTouchMove ( e ) {
@@ -160,6 +161,7 @@ export class SliderComponent implements AfterViewInit, OnDestroy {
160
161
}
161
162
this . isDragging = false ;
162
163
this . move ( ) ;
164
+ this . createSliderInterval ( ) ;
163
165
}
164
166
165
167
private move ( ) {
@@ -208,4 +210,11 @@ export class SliderComponent implements AfterViewInit, OnDestroy {
208
210
return c * Math . sin ( t / d * ( Math . PI / 2 ) ) + b ;
209
211
}
210
212
213
+ private createSliderInterval ( ) {
214
+ clearInterval ( this . movementInterval ) ;
215
+ this . movementInterval = window . setInterval ( ( ) => {
216
+ const newPos = ( this . currentSlidePos === this . slidesNumber ) ? 1 : this . currentSlidePos + 1 ;
217
+ this . setSlideWidthAnimation ( newPos ) ;
218
+ } , this . timeBySlide ) ;
219
+ }
211
220
}
0 commit comments