我正在使用这个 jQuery 来获取视口的大小并将 div 设置为这个大小:
    $("#hero").height($(window).height());
       $(window).resize(function(){
          $("#hero").height($(window).height());
    });
这是我的 HTML:
    <section id="hero">
        Content here
    </section>
    <section class="showcase">
        Content here
    </section>
还有我的 CSS:
body {
 padding: 0;
 margin: 0;
 border: 0;
 background: #f5f6f7;
 color: #fff;
 text-align: center;
}
section {
 width: 100%;
 position: relative;
}
#hero {
 background: black; 
}
.showcase {
     background: blue;
     height: 500px;
}
我不知道为什么这不起作用 - 我对 javascript / jQuery 很陌生,所以也许我错过了一些相当明显的东西。
基本上会发生什么 - 当页面加载 div 看起来像这样:

(该 div 仅包装了“此处的内容”内容 - 例如,没有设置高度)
一旦我抓住浏览器窗口的底部并调整它的大小,div 就会填充视口 - 但我希望 div 立即填充视口,然后允许我向下滚动到下一个 div。
这是带有我的代码的代码笔-但是,该代码似乎可以在此代码笔上使用!?
http://codepen.io/maxwbailey/pen/xDGmy
有人可以就我哪里出错提供解决方案吗?因为我的代码在 Safari chrome 或 firefox 中不起作用,但它在 Code Pen 中起作用。
谢谢