【发布时间】:2014-10-13 20:58:03
【问题描述】:
我的页面上有一个名为“.nav-wrapper”的 div - 此 div 的位置将位于多个位置之一,具体取决于后端的用户设置。我正在尝试做的是使用 jQuery,确定这个 div 的顶部位置,如果它是某个值,则将 margin-top 值添加到不同的 div。
例如,下面我想说如果 .nav-wrapper 顶部位置为 0,则将 .header-wrapper-other 的 min-height 更改为 50px。这是我的代码,但目前它什么也没做:
var MenuPosition = $('.nav_wrapper').css('top').val();
if (MenuPosition == 0) {
$('.header-wrapper-other').css('min-height','50px');
};
这是示例中两个 div 的 css:
.header-wrapper-other {
background-attachment: fixed;
background-size: cover;
min-height: 200px;
}
.nav-wrapper {
padding: 10px 20px;
position: absolute;
top: 0px;
width: 100%;
z-index: 1000;
}
【问题讨论】:
-
也请分享您的 html 代码。如果您可以与您的问题陈述共享 jsfiddle 链接,那就更好了。
-
那么
$('.nav_wrapper').css('top').val()会返回什么?什么类型?