jQuery mobile (click event)

后端 未结 2 504
礼貌的吻别
礼貌的吻别 2021-01-13 13:29

I\'m developing smartphone hybrid applications.

I\'m trying to hide/show a

with slideDown/slideUp.

When I

相关标签:
2条回答
  • 2021-01-13 13:46

    I would suggest using on() instead of bind()

    And since youre doing this:

    var btnMenuDyn = $('a.btnMenuDyn')
    

    btnMenuDyn is a jquery dom element, so change this:

    if ($(menuDyn).hasClass("menuDynHide"))
    

    to this

    if (menuDyn.hasClass("menuDynHide"))
    

    And preferably declare jquery dom elements like this:

    var $btnMenuDyn = $('a.btnMenuDyn')
    
    0 讨论(0)
  • 2021-01-13 14:05

    this problem is mobiles do not support click they use touchstart and touchend so can track movement if you still want to test on computers you can do this

    $(btnMenuDyn).bind('touchstart mousedown', function(event){
        event.preventDefault();
        if ($(menuDyn).hasClass("menuDynHide"))
        {
            $(menuDyn).slideDown().removeClass("menuDynHide");
        }
        else{
            $(menuDyn).slideUp().addClass("menuDynHide");
        }
    
    });
    

    another question with same answer jquery touchstart in browser

    more infomation can be found at http://backtothecode.blogspot.com/2009/10/javascript-touch-and-gesture-events.html

    0 讨论(0)
提交回复
热议问题