forked from Typesetter/Bootstrap-Carousel
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcarousel.js
More file actions
52 lines (48 loc) · 1.6 KB
/
carousel.js
File metadata and controls
52 lines (48 loc) · 1.6 KB
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
/* swipe support from http://wowmotty.blogspot.com/2011/10/adding-swipe-support.html */
var maxTime = 1000, // allow movement if < 1000 ms (1 sec)
maxDistance = 30, // swipe movement of 50 pixels triggers the swipe
startX = 0,
startTime = 0,
touch = "ontouchend" in document,
startEvent = (touch) ? 'touchstart' : 'mousedown',
moveEvent = (touch) ? 'touchmove' : 'mousemove',
endEvent = (touch) ? 'touchend' : 'mouseup';
$(function(){
$('.gp_twitter_carousel').each(function(){
var $carousel = $(this);
var speed = $carousel.data('speed') || 5000;
$carousel
.carousel({interval:speed})
.bind(startEvent, function(e){
// prevent image drag (Firefox)
e.preventDefault();
startTime = e.timeStamp;
startX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX;
})
.bind(endEvent, function(e){
startTime = 0;
startX = 0;
})
.bind(moveEvent, function(e){
e.preventDefault();
var currentX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX,
currentDistance = (startX === 0) ? 0 : Math.abs(currentX - startX),
currentTime = e.timeStamp;
if (startTime !== 0 && currentTime - startTime < maxTime && currentDistance > maxDistance) {
if (currentX < startX) {
$carousel.carousel('next');
}
if (currentX > startX) {
$carousel.carousel('prev');
}
startTime = 0;
startX = 0;
}
})
.filter('.start_paused')
.carousel('pause');
if ( $carousel.find(".item, .carousel-item").length < 2 ){
$carousel.find(".carousel-indicators, .carousel-control").hide();
}
});
});