Ответ 1
100vh
в jQuery просто, как $(window).height()
, тогда как в чистом JavaScript это window.innerHeight
или чуть длиннее.
jQuery(function($) {
var $nav = $('#verschwinden');
var $win = $(window);
var winH = $win.height(); // Get the window height.
$win.on("scroll", function () {
if ($(this).scrollTop() > winH ) {
$nav.addClass("doch");
} else {
$nav.removeClass("doch");
}
}).on("resize", function(){ // If the user resizes the window
winH = $(this).height(); // you'll need the new height value
});
});
вы также можете сделать часть if
немного короче, просто используя:
$nav.toggleClass("doch", $(this).scrollTop() > winH );