forked from kbasten/JS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslider.js
More file actions
41 lines (30 loc) · 948 Bytes
/
slider.js
File metadata and controls
41 lines (30 loc) · 948 Bytes
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
var slideTimeOut = 8000; // delay between slide changes
var slideTime = 500; // animation time
var slideWidth; // width of a single slide in px
var slideId;
var curSlide = 0;
var numSlides;
var direction = 1; // 1 = right, -1 = left, init direction
var slideTimer;
jQuery(document).ready(function(){
slideId = jQuery("#slidercontent");
slideWidth = slideId.children().eq(0).width();
numSlides = slideId.children().length;
slideId.css("width", (numSlides * slideWidth) + "px");
slideTimer = setTimeout('nextSlide()', slideTimeOut);
});
function nextSlide(){
if (curSlide >= numSlides - 1){
direction = -1; // reverse direction
}
if (curSlide <= 0){
direction = 1; // reverse direction
}
curSlide+= direction;
toSlide(curSlide);
slideTimer = setTimeout('nextSlide()', slideTimeOut);
}
function toSlide(nr){
var newMargin = slideWidth * nr;
slideId.animate({ "margin-left": "-" + newMargin + "px" }, slideTime);
}