移动隐藏菜单适用于jsfiddle,但不适用于在线.任何解决方案都会有所帮助

Mobile Hidden Menu works on jsfiddle but not online. Any solution would be helpful.

本文关键字:适用于 解决方案 帮助 任何 在线 jsfiddle 隐藏菜单 不适用 移动      更新时间:2023-09-26

所以,我使用了以下URL的根JS小提琴(761之前的部分),我得到了一个很好的设计,完全按照我想要的方式工作。这是链接:

点击这里查看整个JSFiddle,这是Javascript代码:

$('#trigger').click( function() {
    if ($('#popout').hasClass('hidden')) {
        $('#popout').removeClass('hidden');
        showPopout();
    }
    else {
        $('#popout').addClass('hidden');
        hidePopout();
    }
});
function showPopout() {
    $('#popout').animate({
        top: 49
    }, 'slow', function () {
        $('#trigger span').html('|||');  //change the trigger text at end of animation
    });
}
function hidePopout() {
    $('#popout').animate({
        top: -150
    }, 'slow', function () {
        $('#trigger span').html('|||');  //change the trigger text at end of animation
    });
}

但是当我在这里实现它时:http://m.bwpcommunications.com/agency.php 它不起作用。

有人知道为什么会这样吗?

看起来您可能在加载 DOM 之前设置了单击处理程序。

你可以看到,通过改变你的小提琴来加载jQuery"在头上"(就像你的实时网站一样),你的代码停止工作。http://jsfiddle.net/tzDjA/764/

您可能需要在点击处理程序周围添加以下内容.
这将在加载 DOM 后配置您的处理程序。

$(function() {
  $('#trigger').click( function() {
    [...]
  }  
});

http://jsfiddle.net/tzDjA/762/

或者,尝试委派处理程序,以便将其应用于稍后添加到 DOM 的元素。

$(document).on('click','#trigger',function() {
  [...]
});

http://jsfiddle.net/tzDjA/763/

你需要在这个页面上加载jQuery: http://m.bwpcommunications.com/agency.phpjQuery UI不等同于jQuery。

https://developers.google.com/speed/libraries/devguide#jquery