Reputation: 45
$(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? I don't have much jQuery experience.
Upvotes: 2
Views: 18926
Reputation: 18238
VH : Viewport Height is similar to $(window).height();
Source
So you can check the condition if (windowHeight > 0.1)
then
$("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
Upvotes: 8
Reputation: 357
I believe the correct syntax is
$(selector).attr(attribute,value)
So for your specific example $(document).attr('height','100vh')
Here is a link that hopefully helps --> https://www.w3schools.com/jquery/html_attr.asp
Upvotes: 1