我已经完成了一个导航,当使用 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/