-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
28 lines (22 loc) · 799 Bytes
/
index.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
var carouselWidth = $('.carousel')[0].scrollWidth;
var cardWidth= $('.card').width();
console.log(cardWidth);
console.log(carouselWidth);
var scrollPosition = 0;
$('.carousel-control-next').on('click', function(){
console.log(scrollPosition);
console.log(carouselWidth - (cardWidth * 4));
if(scrollPosition < (carouselWidth - (cardWidth))){
console.log("here");
scrollPosition = scrollPosition + cardWidth;
$('.carousel-inner').animate({scrollLeft: scrollPosition},600);
}
});
$('.carousel-control-prev').on('click', function(){
console.log(scrollPosition);
if(scrollPosition > 0){
console.log("prev");
scrollPosition = scrollPosition - cardWidth;
$('.carousel-inner').animate({scrollLeft: scrollPosition},600);
}
});