0

In a div I have three absolute divs that should scroll in my container to gain a small parallax effect. I made a function to track the offset of e.pageX on mousedown. If the mouse comes up before there is dragged I register it as a click event (that checks if someone clicked on the left or right side of the screen).

QUESTION: This doesnt work on iPad. I tried a lot of solutions I found on this site, but I couldnt get it to work.

Could you guys point me to a working function for this on iPad?

var isDragging = false;
var currentPosition = 0;
var startClick = 0;
var showcaseWidth = $('#showcase').width();
var direction = "";

$('#showcase')
.mousedown(function(e) {
    startClick = e.pageX;
    $(window).mousemove(function(e) {
        isDragging = true;
        var x = e.pageX;
        userIsDragging(x);
    });
    return false;
})
.mouseup(function(e) {
    var wasDragging = isDragging;
    isDragging = false;
    $(window).unbind("mousemove");
    if (!wasDragging) { //was clicking
        var x = e.pageX;
        if(x>(showcaseWidth/2))
            $("#tracker").text("go left");// bijvoorbeeld userIsDragging 1024px of naar t volgende snap punt
        else
            $("#tracker").text("go right");

    }
});
function userIsDragging(x) {
    var movement = x - startClick;
    $("#tracker").text(movement);
}
Hans Wassink
  • 2,529
  • 3
  • 30
  • 45

1 Answers1