[英]How do I get document height using vh units in jQuery?
$(window).scroll(function() {
$scrollingDiv.css("display", (($(window).scrollTop() / $(document).height()) > 0.1) ? "block" : "");
});
How can I change the unit $(document).height()) > 0.1)
to 100vh? 如何将单位$(document).height()) > 0.1)
更改为100vh? I don't have much jQuery experience. 我没有太多的jQuery经验。
VH : Viewport Height is similar to $(window).height();
VH :视口高度类似于$(window).height();
Source 资源
So you can check the condition if (windowHeight > 0.1)
then 所以你可以检查条件if (windowHeight > 0.1)
然后
$("body").height(windowHeight);
Code: 码:
$(document).ready(function() {
var windowHeight = $(window).height();
if (windowHeight > 0.1) {
alert("height is greater than 0.1");
$("body").height(windowHeight);
} else {
alert("height is less than 0.1");
}
});
Codepen link: https://codepen.io/anon/pen/GWzVwO Codepen链接: https ://codepen.io/anon/pen/GWzVwO
I believe the correct syntax is $(selector).attr(attribute,value)
So for your specific example $(document).attr('height','100vh')
我相信正确的语法是$(selector).attr(attribute,value)
所以对于你的具体例子$(document).attr('height','100vh')
Here is a link that hopefully helps --> https://www.w3schools.com/jquery/html_attr.asp 这是一个希望有用的链接 - > https://www.w3schools.com/jquery/html_attr.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.