0

I am trying to execute a function on pinch in of the body and then another function on pinch out. Since i'm already using jquery.hammer.js in this document and hammer can listen for in and out pinches, I thought it would be best to use it to listen for the pinches. But, instead of running the functions, I would just run alerts instead for now.

This seems like it should work, but when I pinch in and pinch out, the alerts are not fired.

What am I doing wrong?

Here is my code:

<!Doctype HTMl>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Pinch me!</title>
    </head>
    <body>

        <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script type="text/javascript" src="//raw.github.com/EightMedia/hammer.js/master/dist/jquery.hammer.min.js"></script>
        <script type="text/javascript">
        var element = $('body').get();
        var hammertime = Hammer(element).on("pinchin", function(event) {
            alert("pinch in!");
        });
        var hammertimes = Hammer(element).on("pinchout", function(event) {
            alert("pinch out!");
        });
        </script>
    </body>
</html>

I would greatly appreciate any help in getting these alerts to fire on pinch in and out.

2 Answers 2

1

I think your script is just malformed? .get() is for making Ajax calls. To select an element, you just wrap it in the jQuery selector.

Try setting element like this -

var element = $('body');

It's not clear to me why you're binding the pinch events to variables in this simple example either, but it shouldn't stop it from working.

6
  • ah, I didn't know that. I didn't know that one could just wrap an element in the jQuery selector. I bounded the events to variables because the documentation did. It is still not working, however.
    – IMUXIxD
    Commented Mar 17, 2013 at 23:46
  • It's possible the pinch might not register on the body element. I'd try adding some elements to the page and binding the pinch to them.
    – iabw
    Commented Mar 18, 2013 at 16:07
  • I hadn't thought of that, but I tried it and it didn't make a difference :-(
    – IMUXIxD
    Commented Mar 18, 2013 at 19:31
  • Do you have any other ideas? So far, what I have and what does't work, is at the-irf.com/pinch.html
    – IMUXIxD
    Commented Mar 20, 2013 at 19:14
  • @IMUXIxD Why did you mark this as the answer but in the comments it's clear that this didn't work for you?!? Commented Jul 29, 2013 at 14:40
0

You don't need jQuery here. Just use Hammer(document.body).on(...)

1
  • Ah, okay. Thank you. Except, it is still not working. Here is a live example: the-irf.com/pinch.html
    – IMUXIxD
    Commented Mar 17, 2013 at 23:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.