【问题标题】:jquery mmenu.js on single page website单页网站上的 jquery mmenu.js
【发布时间】:2013-06-27 08:56:02
【问题描述】:

我已经在jsFiddle 上设置了我的问题示例: 也可以全屏查看,因为示例是responsive

当我在激活 mmenu 时单击菜单项后会发生什么,滚动跳转到随机锚点,而不是正确的锚点。有人可以帮忙吗?

我有 jquery 1.9.1、mmenu.js 和 jqueryeasing,这些是内联脚本

$(function() {
            $('nav ul li a').bind('click',function(event){
                var $anchor = $(this);
                $('html, body').stop().animate({
                    scrollTop: $($anchor.attr('href')).offset().top
                }, 1000,'easeInOutExpo');
                event.preventDefault();
            });
        });



        $(function() {
            $('nav#nav').mmenu({
                configuration: {
                    //  For some odd reason, the header won't stay "fixed"
                    //  when using hardware acceleration
                    hardwareAcceleration: false
                }
            });
        });

【问题讨论】:

    标签: jquery mobile menu navigation


    【解决方案1】:

    没有人回答,但我想分享修复。 mmenu 的创建者 Fred 非常友好地通过电子邮件提供了一些支持,您可以在此处查看修复:http://jsfiddle.net/9FdXv/8/

    这里是js:

    $(function() {
                $('nav ul li a').bind('click',function(event){
                    var $anchor = $(this);
    
                    $('nav#nav').one('closed.mmenu', function() {
                        setTimeout(function() {
                            $('html, body').stop().animate({
                                scrollTop: $($anchor.attr('href')).offset().top
                            }, 1000,'easeInOutExpo');
                        }, 10);
                    });
                    $('nav#nav').trigger('close.mmenu');
    
                    event.preventDefault();
                    event.stopImmediatePropagation();
                });
            });
    
    
    
            $(function() {
                $('nav#nav').mmenu({
                    configuration: {
                        //  For some odd reason, the header won't stay "fixed"
                        //  when using hardware acceleration
                        hardwareAcceleration: false
                    }
                });
            });
    

    希望这对其他人有所帮助

    【讨论】:

    • 我遇到了类似的问题:当我通过在同一个菜单之外单击关闭菜单时,我的页面返回顶部,而不是在菜单选择的锚点上保留。您对此有任何想法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多