如何连续检查网页的当前窗口高度?

时间:2016-06-20 11:16:35

标签: css height

我在网站上有一个导航栏,并且在到达高度的某个点(y轴)之后。我想操纵导航栏的css代码,例如背景颜色。

到目前为止这么好,我用if语句检查高度,如果它克服了某个值我操纵了navbar类的css ....但是我如何确保不断检查我已经使用了setInterval方法,但我不确定这是否是一个很好的解决方案......谁能帮助我?

提前致谢!

<div style='width:80px;height:200px;overflow:scroll;'>
<div class="testing"><input type="checkbox" value='All'> All</div>
<div class="testing"><input type="checkbox" value='San Francisco'> San Francisco</div>
<div class="testing"><input type="checkbox" value='North Carolina'> North Carolina</div>
<div class="testing"><input type="checkbox" value='New York'> New York</div>
</div>

2 个答案:

答案 0 :(得分:1)

您可以使用jQuery这样做:

example.com/photo.jpg?ts=12345

使用CSS $(window).resize(function () { if ($(window).height()>600) { $(".class").css({"background-color":"blue"}); } else { $(".class").css({"background-color":"transparent"}); } }); 标签时,您也可以在不使用jquery的情况下执行此操作:

@media

答案 1 :(得分:0)

如果你想在屏幕太小时更改CSS,你可能不需要jQuery:

@media screen and (max-height: 600px) {
  .class {background-color:transparent}
}