-
Notifications
You must be signed in to change notification settings - Fork 0
/
slider.js
54 lines (33 loc) · 928 Bytes
/
slider.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
//function passes the pics one by one at an interval of 3 seconds ,
//which is approx time a pic that is already passed takes to slide away
var slidePic = function(){
var pics = [document.getElementById("pic1"),document.getElementById("pic2"),document.getElementById("pic3")];
var i =0;
var int = setInterval(function(){
if(i > 2){
i = 0;
}
pics[i].style.zIndex = 99;
slide(pics[i]);
i++;
},3000);
}
//function to slide an element that is passed on to it
var slide = function(picture){
'use strict';
var pixel = -150;
var interval = setInterval(function(){
if(picture.style.left != '150px'){
picture.style.left = pixel.toString() + 'px';
}
pixel += 1;
//pixel2 +=1;
if(picture.style.left == '150px'){
picture.style.left = '-150px';
pixel = -150;
picture.style.zIndex = 0;
clearInterval(interval);
}
},16.66);
}
window.onload = slidePic;