下拉菜单无法在移动设备上运行

时间:2017-07-21 14:10:21

标签: html css3

我已经搜索过高低,并从这里尝试了许多不同的选项,但我现在需要一个正确的方向点:)

在这个网站上:

http://www.michael-smith-engineers.co.uk

在主导航中,(在移动视图中)如果单击Pumps,则应该有进一步的下拉选项,但我无法使其正常工作。任何想法都将不胜感激。

我试过添加以下脚本,没有任何运气......

<script>
// see whether device supports touch events (a bit simplistic, but...)
var hasTouch = ("ontouchstart" in window);
var iOS5 = /iPad|iPod|iPhone/.test(navigator.platform) && "matchMedia" in window;

// hook touch events for drop-down menus
// NB: if has touch events, then has standards event handling too
// but we don't want to run this code on iOS5+
if (hasTouch && document.querySelectorAll && !iOS5) {
    var i, len, element,
        dropdowns = document.querySelectorAll("#nav-site li.children > a");

    function menuTouch(event) {
        // toggle flag for preventing click for this link
        var i, len, noclick = !(this.dataNoclick);

        // reset flag on all links
        for (i = 0, len = dropdowns.length; i < len; ++i) {
            dropdowns[i].dataNoclick = false;
        }

        // set new flag value and focus on dropdown menu
        this.dataNoclick = noclick;
        this.focus();
    }

    function menuClick(event) {
        // if click isn't wanted, prevent it
        if (this.dataNoclick) {
            event.preventDefault();
        }
    }

    for (i = 0, len = dropdowns.length; i < len; ++i) {
        element = dropdowns[i];
        element.dataNoclick = false;
        element.addEventListener("touchstart", menuTouch, false);
        element.addEventListener("click", menuClick, false);
    }
}
</script>

上面的这个脚本对我的尝试非常荒谬,试过这个:

<script type="text/javascript">
     function is_touch_device() {

     return (('ontouchstart' in window) || (navigator.MaxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0));
  }

  if(is_touch_device()) {

    jQuery('.toggle-menu').on('click', function(){

      jQuery(this).toggleClass('activate');

      jQuery(this).find('ul').slideToggle();
      return false;
    });
  } 
</script>

</head>

仍然没有运气?!!!!

0 个答案:

没有答案