source: HomeSlider.js

Last change on this file was e3d4e0a, checked in by Vlado 222039 <vlado.popovski@…>, 6 days ago

Upload project files

  • Property mode set to 100644
File size: 1.4 KB
Line 
1var 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
8let timeRunning = 3000
9let timeAutoNext = 7000
10
11nextButton.onclick = function(){
12 showSlider('next')
13}
14
15prevButton.onclick = function(){
16 showSlider('prev')
17}
18
19let runTimeOut
20let runNextAuto = setTimeout(() =>{
21 nextButton.click()
22}, timeAutoNext)
23
24function 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
32function 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
58resetTimeAnimation()
Note: See TracBrowser for help on using the repository browser.