-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
113 lines (88 loc) · 2.42 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var models = [
{
name : 'Bmw 418d',
image : 'img/bmw.jpg',
link : 'http://www.arabalar.com.tr/bmw/4-serisi/2018/418d-2-0-gran-coupe'
},
{
name : 'Mazda CX-3',
image : 'img/mazda.jpg',
link : 'http://www.arabalar.com.tr/mazda/cx-3/2017/1-5-sky-d-motion'
},
{
name : 'Volvo S60',
image : 'img/volvo.jpg',
link : 'http://www.arabalar.com.tr/volvo/s60/2018/1-5-t3-advance'
},
{
name : 'Skoda Superb',
image : 'img/skoda.jpg',
link : 'http://www.arabalar.com.tr/skoda/superb/2018/1-4-tsi-active'
},
{
name : 'Honda Civic',
image : 'img/honda.jpg',
link : 'http://www.arabalar.com.tr/honda/civic/2018/1-6-elegance'
}
];
var index = 0;
var slaytCount = models.length;
var interval;
var settings={
duration : '2000',
random : false
};
init(settings);
document.querySelector('.fa-arrow-circle-left').addEventListener('click',function(){
index--;
showSlide(index);
console.log(index);
});
document.querySelector('.fa-arrow-circle-right').addEventListener('click',function(){
index++;
showSlide(index);
console.log(index);
});
document.querySelectorAll('.arrow').forEach(function(item){
item.addEventListener('mouseenter',function(){
clearInterval(interval);
})
});
document.querySelectorAll('.arrow').forEach(function(item){
item.addEventListener('mouseleave',function(){
init(settings);
})
})
function init(settings){
var prev;
interval=setInterval(function(){
if(settings.random){
// random index
do{
index = Math.floor(Math.random() * slaytCount);
}while(index == prev)
prev = index;
}else{
// artan index
if(slaytCount == index+1){
index = -1;
}
showSlide(index);
console.log(index);
index++;
}
showSlide(index);
},settings.duration)
}
function showSlide(i){
index = i;
if (i<0) {
index = slaytCount - 1;
}
if(i >= slaytCount){
index =0;
}
document.querySelector('.card-title').textContent = models[index].name;
document.querySelector('.card-img-top').setAttribute('src',models[index].image);
document.querySelector('.card-link').setAttribute('href',models[index].link);
}