I'm trying to activate a menu with jQuery with a click (touch) on mobile, but it is not working in mobile. When I do the 'window' resize to try the mobile look, it works with the click, but in an emulator or even trying it with my phone, it doesn't work.

我试着在移动设备上点击(触摸)来激活jQuery菜单,但是它在移动设备上不工作。当我做“窗口”调整大小以尝试移动外观时,它可以通过点击来工作,但在模拟器中,甚至在我的手机中,它都不能工作。

HTML Markup

HTML标记

<img src="i/mobilemenu.jpg" id="mobileMenuButton" style="position:absolute; right:0;"/>

CSS:

CSS:

#mobileNavigation {display:none}

Javascript Code:

Javascript代码:

<script type="text/javascript">
            $(document).ready(function(){
                    $('#mobileMenuButton').on('click touchstart',function(){

                            if ($('#mobileNavigation').css('display') == 'none') {
                                $('#mobileNavigation').css('display','block');
                            } 
                            else 
                            {
                                    $('#mobileNavigation').css('display','none'); }
                            });
                    });
                </script>

4 个解决方案

#1


0

<script type="text/javascript">
   $(document).ready(function(){
      $('#mobileMenuButton').on('mousedown touchstart',function(){
            var userAgent = window.navigator.userAgent;
            if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)||  userAgent.match(/Android/i)) {
         if ($('#mobileNavigation').css('display') == 'none') {
            $('#mobileNavigation').css('display','block');
         } else {
            $('#mobileNavigation').css('display','none'); 
         }
       }
      });
   });
</script>

Just provide the user agent.

只需提供用户代理。

更多相关文章

  1. 如何在git特性分支工作流中处理xml/html ?
  2. 儿童视图不在angular-ui-router中工作
  3. 为什么ng-hide和ng-show不工作?
  4. 如何使flex box在safari中工作?
  5. XSL:包括根本不工作
  6. 缓存js / css资源以使我的项目脱机工作
  7. 网页语言有html,php.jsp,无论什么语言浏览器总是能正常显示,这个解
  8. 不能让align-self在flexbox容器中工作
  9. 为什么css不能与这个div一起工作?

随机推荐

  1. Android 快速运行的秘诀
  2. 向eclipse中导入android中的sample样例+g
  3. Android(安卓)View requires API level 1
  4. Android开发实现二级联动下拉列表
  5. android:shrinkColumns的用法 (2011-04-2
  6. android OkHttp3
  7. activity
  8. xposed框架的检测和反制
  9. Android编程简单设置ListView分割线的方
  10. AndroidStudio 开发自我小结(1)