I am getting the Error: Uncaught TypeError: Object [object Object] has no method 'addEventListener' hammer.js:168
my code is like this:
<script type="text/javascript" src="js/hammer.js"></script>
On device ready function:
var resim = $('#kaydir');
Hammer(resim).on('swipeleft', function(ev){
console.log('left: ', ev);
});
It seems the error is in hammer.js . What should I do?
I imagine your issue is that you don't have Hammer.js's jQuery Plugin installed (GitHub).
Because of this, you cannot pass a jQuery object into the Hammer()
function, your two options:
Add the jQuery Plugin I've linked to above to your project, then call:
$('#kaydir').Hammer(...)
Pass only the element into Hammer()
and not the jQuery object, by using [0]
:
Hammer(resim[0]).on(...)
Or instead change your resim
variable to hold the result of calling JavaScript's getElementById
.
var resim = document.getElementById('kaydir');
Hammer(resim).on(...)
If you are using jQuery, you should use the jQuery Hammer version and use it like that:
var resim = $("#kaydir");
resim.hammer().on("swipeleft", function(ev) {
console.log('left: ', ev);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With