1 | var nextButton = document.querySelector('.next'),
|
---|
2 | prevButton = document.querySelector('.prev'),
|
---|
3 | mainSection = document.querySelector('.main-home'),
|
---|
4 | list = document.querySelector('.list'),
|
---|
5 | item = document.querySelectorAll('.item'),
|
---|
6 | runningTime = document.querySelector('.timeRunning')
|
---|
7 |
|
---|
8 | let timeRunning = 3000
|
---|
9 | let timeAutoNext = 7000
|
---|
10 |
|
---|
11 | nextButton.onclick = function(){
|
---|
12 | showSlider('next')
|
---|
13 | }
|
---|
14 |
|
---|
15 | prevButton.onclick = function(){
|
---|
16 | showSlider('prev')
|
---|
17 | }
|
---|
18 |
|
---|
19 | let runTimeOut
|
---|
20 | let runNextAuto = setTimeout(() =>{
|
---|
21 | nextButton.click()
|
---|
22 | }, timeAutoNext)
|
---|
23 |
|
---|
24 | function resetTimeAnimation() {
|
---|
25 | runningTime.style.animation = 'none'
|
---|
26 | runningTime.offsetHeight
|
---|
27 | runningTime.style.animation = null
|
---|
28 | runningTime.style.animation = 'runningTime 7s linear 1 forwards'
|
---|
29 | }
|
---|
30 |
|
---|
31 |
|
---|
32 | function showSlider(type){
|
---|
33 | let sliderItemsDom = list.querySelectorAll('.main-home .list .item')
|
---|
34 | if(type === 'next'){
|
---|
35 | list.appendChild(sliderItemsDom[0])
|
---|
36 | mainSection.classList.add('next')
|
---|
37 | } else{
|
---|
38 | list.prepend(sliderItemsDom[sliderItemsDom.length - 1])
|
---|
39 | mainSection.classList.add('prev')
|
---|
40 | }
|
---|
41 |
|
---|
42 | clearTimeout(runTimeOut)
|
---|
43 |
|
---|
44 | runTimeOut = setTimeout( () => {
|
---|
45 | mainSection.classList.remove('next')
|
---|
46 | mainSection.classList.remove('prev')
|
---|
47 | }, timeAutoNext)
|
---|
48 |
|
---|
49 |
|
---|
50 | clearTimeout(runNextAuto)
|
---|
51 | runNextAuto = setTimeout(() =>{
|
---|
52 | nextButton.click()
|
---|
53 | }, timeAutoNext)
|
---|
54 |
|
---|
55 | resetTimeAnimation()
|
---|
56 | }
|
---|
57 |
|
---|
58 | resetTimeAnimation() |
---|