jQM - Touchstart/Touchend Demo

by Dragan Gaić

HTML

<link rel="stylesheet" href="http://jeromeetienne.github.com/jquery-mobile-960/css/jquery-mobile-fluid960.css">
<!DOCTYPE html>
<html>
<head>
    <title>jQM Complex Demo</title>
    <meta name="viewport" content="width=device-width"/>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>    
</head>
<body>
    <div data-role="page" id="index">
        <div data-theme="a" data-role="header">
            <h3>
                First Page
            </h3>
            <a href="#second" class="ui-btn-right">Next</a>
        </div>

        <div data-role="content">
           <input type="input" id="start"><br>
           <input type="input" id="move-x">
            <input type="input" id="move-y"><br>
           <input type="input" id="end">
        </div>

        <div data-theme="a" data-role="footer" data-position="fixed">

        </div>
    </div>   
</body>
</html>

CSS

#justify-div {
    width: 160px; margin:0px auto
}

JavaScript

$('#index').live('touchstart vmousedown', function(){
        $('#start').val('Touch start');
    })

    $('#index').live('touchmove vmousemove', function(event){
        $('#move-x').val(event.pageX);
        $('#move-y').val(event.pageY);
    })
        
    $('#index').live('touchend vmouseup', function(){
        $('#end').val('Touch end');
    });