繁体   English   中英

Javascript移动导航菜单

[英]Javascript mobile navigation menu

我正在关注在线Lynda.com教程,该教程通过Javascript和JQuery格式化移动导航菜单。 第一步是下载JQuery,将JQuery和Javascript挂接到我的HTML中,并用警报检查该文档,该方法可以正常工作,但是随后我需要在下面键入代码。但该功能不起作用。 任何人都可以在代码中看到任何错误吗? 谢谢。

/ * JavaScript文档* /

$(document).ready(function(){

    $('nav a.mobile_menu').on('click',function(){

        var currentNavHeight = $('nav').height(); 

        if( currentNavHeight < 5  ){  

                var newNavHeight = $('nav > ul').height() + 15;
                $('nav').animate({'height':newNavHeight+'px'},750);

        }else{

            $('nav').animate({'height':'0px'},750,function(){
                $(this).removeAttr('style');
            });
        }
    });

    $(window).resize(function(){

        if( $(this).width() > 625 ){
            $('nav').removeAttr('style');

        }
});

除非提供的代码示例不完整,否则您没有$(window).resize函数或包装$(document).ready函数的$(window).resize括号。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM