<h3 class="text-center pt-2">Carousel mousemove/touchmove change item</h3>
<div id="carouselExampleIndicators" class="carousel slide col-10 mx-auto pt-2 grab" data-ride="carousel" data-interval="false">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://fakeimg.pl/1200x200/?text=Hello" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="https://fakeimg.pl/1200x200/?text=bootstrap" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="https://fakeimg.pl/1200x200/?text=mousemove" class="d-block w-100" alt="...">
</div>
</div>
<!-- <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a> -->
</div>
$('#carouselExampleIndicators').on('touchstart mousedown', function(event) {
var xClick;
if (event.type == 'touchstart') {
xClick = event.originalEvent.touches[0].pageX;
} else {
xClick = event.originalEvent.pageX;
}
$(this).on('touchmove mousemove', function(event) {
var xMove;
if (event.type == 'touchmove') {
xMove = event.originalEvent.touches[0].pageX;
} else {
xMove = event.originalEvent.pageX;
}
const sensitivityInPx = .5;
if (Math.floor(xClick - xMove) > sensitivityInPx) {
$(this).carousel('next');
} else if (Math.floor(xClick - xMove) < -sensitivityInPx) {
$(this).carousel('prev');
}
});
$(this).on('touchend mouseover', function() {
$(this).off('touchmove mousemove');
});
});