Skip to content

Instantly share code, notes, and snippets.

@sourcepirate
Created March 2, 2016 02:41
Show Gist options
  • Save sourcepirate/1a746e52b3b7a9647912 to your computer and use it in GitHub Desktop.
Save sourcepirate/1a746e52b3b7a9647912 to your computer and use it in GitHub Desktop.
var $j = jQuery.noConflict();
var down_x = null;
var up_x = null;
$j().ready(function(){
$j("#slider > div").mousedown(function(e){
e.preventDefault();
down_x = e.pageX;
});
$j("#slider > div").mouseup(function(e){
up_x = e.pageX;
do_work();
});
$j("#slider > div").bind('touchstart', function(e){
down_x = e.originalEvent.touches[0].pageX;
});
$j("#slider > div").bind('touchmove', function(e){
e.preventDefault();
up_x = e.originalEvent.touches[0].pageX;
});
$j("#slider > div").bind('touchend', function(e){
do_work();
});
});
function do_work()
{
if ((down_x - up_x) > 50)
{
slide_right();
}
if ((up_x - down_x) > 50)
{
slide_left();
}
}
function slide_right()
{
$j("#slider_content").animate({scrollLeft:'+=300'},1000);
}
function slide_left()
{
$j("#slider_content").animate({scrollLeft:'-=300'},1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment