How do I get document height using vh units in jQuery?

Luke Cooper picture Luke Cooper · Apr 2, 2017 · Viewed 14.1k times · Source
$(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.

Answer

Suresh Karia picture Suresh Karia · Apr 3, 2017

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