The Hammer.js JavaScript library allows us to handle gesture touch events that take place when running our code on a touch screen device.

The following code sample shows how simple it is to use this library. You just need to pass over the name of the gesture touch event you want to handle and the function you want to be invoked when that event takes place.

<!DOCTYPE html>
<html>
<head>
    <title>hammer.js demo</title>
    <script src="hammer.min.js" type="text/javascript"></script>
</head>
<body>
    <div id="something"><h1>something</h1></div>
    <script type="text/javascript">
        var element = document.getElementById('something');
        Hammer(element).on("drag", function(event) {
                                        alert("drag!");
                                    });
        Hammer(element).on("tap", function(event) {
            alert("tap!");
        });
    </script>
</body>
</html>

The following video clip overviews this code sample, shows its execution and explains it step by step.

You can find more video clips, code samples and various other training material for learning how to use this JavaScript library in my free courses web site at http://abelski.lifemichael.com.

Leave a Reply

Your email address will not be published. Required fields are marked *