Created
March 27, 2017 22:56
-
-
Save derekbtw/688d1437775fb86e1c9d8fa03aa1b645 to your computer and use it in GitHub Desktop.
Add swipe functionality to Bootstrap's carousel slider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".carousel").on("touchstart", function(event){ | |
var xClick = event.originalEvent.touches[0].pageX; | |
$(this).one("touchmove", function(event){ | |
var xMove = event.originalEvent.touches[0].pageX; | |
if( Math.floor(xClick - xMove) > 5 ){ | |
$(".carousel").carousel('next'); | |
} | |
else if( Math.floor(xClick - xMove) < -5 ){ | |
$(".carousel").carousel('prev'); | |
} | |
}); | |
$(".carousel").on("touchend", function(){ | |
$(this).off("touchmove"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment