jQuery functions not working with Hammer.js

后端 未结 2 1921
野的像风
野的像风 2021-01-27 02:41

I am trying to add press to jQuery selector. I have many elements on same document, So I can not use IDs for each. I tried by $(selector)[i] as like ex

相关标签:
2条回答
  • 2021-01-27 03:04

    Finally I solved the problem by using each function

    $('.mh60 a').each(function(){
        var mc = new Hammer(this);
        var currentEle = $(this);
        mc.on("press", function() {
          currentEle.addClass('active');
        });
     });
    
    0 讨论(0)
  • 2021-01-27 03:23

    Why do you use a for? Try changing your code like this

    var selectProduct = $('.mh60 a');
    selectProduct.Hammer().on("press", function() {
      $(this).addClass('active');
    });
    
    0 讨论(0)
提交回复
热议问题