javascript - 绑定(bind)调整大小时删除高度属性

标签 javascript jquery

我已经完成了一个导航,当使用 jquery 完成移动 View 时,该导航可以显示完整文档。

我正在尝试取消高度以恢复为自动,或者只是删除以前的 jquery 给出的样式属性。

但由于某种原因它不起作用,我尝试了一些方法,但它根本不起作用。

如果通过jquery给的style属性可以不取消吗?

这是在移动 View 中打开和关闭导航的导航:

// Mobile Navigation Area
jQuery('.menu-icon-mobile').on('click',function(event){

    event.preventDefault();

    var currentId = jQuery(this).attr('id');
    var mobileHeight = jQuery(document).height();

    switch (currentId){

        case 'mobile-nav-open':{

            jQuery('.navigation').animate({height: mobileHeight + "px"}, 400 );
            jQuery(this).attr('id','mobile-nav-close');

        }
        break;

        case 'mobile-nav-close':{

            jQuery('.navigation').animate({height: "0px"}, 400 );
            jQuery(this).attr('id','mobile-nav-open');

        }
        break;

    }

});

这是调整大小的代码,我添加了警报以显示其已绑定(bind)并且它是:(

//checking if the screen is resized and if it is and the screen is less that 768px wide then cancel the attributes
jQuery(window).resize(function(){

    var thescreen = jQuery(window).width();

    if(thescreen > 768){

        jQuery('.navigaiton').removeAttr('style');

    }

    alert(thescreen);
});

据我所知,这应该可行,我唯一能想到的是,样式属性在现实生活中并不存在,因为它是使用 jquery 完成的,所以它看不到样式属性来删除它。

知道如何删除给定的属性吗?

这是 jsfiddle 链接:

http://jsfiddle.net/robertg/kn1scc2f/2/

谢谢

最佳答案

您的选择器拼写错误。

更改:

jQuery('.navigaiton')

致:

jQuery('.navigation')

关于javascript - 绑定(bind)调整大小时删除高度属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26355097/

相关文章:

javascript - Modal 触发时自动播放视频

php - 显示数据库表中的两个字段以填充 jquery 自动完成

javascript - 使用 jquery 或 javascript 在 wordpress 中获取 pagetitle

ruby-on-rails - Rails 可以让 Ajax 保持开放多长时间

javascript - 服务人员和 Django

javascript - ScrollTo 适用于所有浏览器,但完整回调会多次触发

javascript - JQuery 在 ajax 加载数据库后不起作用

javascript ajax 无法正常工作

javascript - 无法使用 jQuery 更改输入的 defaultValue 属性

javascript - 仅在禁用 Flash 时显示颜色框关闭按钮