detect touchmove

by Oliver Kelso

HTML

<div id="test-div">test div</div>

CSS

#test-div{
    width:400px;
    height:400px;
    background:green;
    color:#FFFFFF;
}

JavaScript

var dragging = false;
    
    // set dragging to true on touchmove event
    $("body").on("touchmove", function () {
        dragging = true;
    });

    
    $("#test-div").on("touchend", function (e) {
        e.preventDefault();

        if (dragging == true) {
            
            alert("true");

        } else {
            
            alert("false");

        }

        dragging = false;
    });