【发布时间】:2011-08-10 10:24:03
【问题描述】:
我有一个 div 容器,它的上边距应该设置为 $(window).height() 的依赖项,所以首先我尝试了这样的事情:
$("div#outerstart").css("margin-top",$(window).height() -805+"px");
效果很好,但 margin-top 不应该是负数,所以我尝试了这个:
$("div#outerstart").css("margin-top",function () {
if ($(window).height() < 805) {
0+"px"
} else {
$(window).height() -805+"px"
}
});
也可以
if ($(window).height() < $(document).height()) {...
但它没有显示任何效果并且没有设置margin-top。你有什么建议吗?
【问题讨论】:
-
使用return关键字?它的功能,而不是直接声明
-
@Marek Sebera:写一个答案而不是评论?