简体   繁体   中英

Javascript mobile navigation menu

I am following an online Lynda.com tutorial where I am formatting a mobile navigation menu via Javascript and JQuery. The first step was downloading JQuery, hooking JQuery and Javascript into my HTML and checking the document with an alert, which worked, but then I needed to type out code below....I have checked it numerous times and cannot see any errors, but the function is not working. Can anyone else see any errors in the code? Thank you.

/* JavaScript Document */

$(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括号。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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