Kev*_*aca 12 javascript height scroll viewport
如何使此功能在滚动后添加类100vh?
目前它增加了课程850px.
$("document").ready(function($){
var nav = $('#verschwinden');
$(window).scroll(function () {
if ($(this).scrollTop() > 850) {
nav.addClass("doch");
} else {
nav.removeClass("doch");
}
});
});
Run Code Online (Sandbox Code Playgroud)
Rok*_*jan 19
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
});
});
Run Code Online (Sandbox Code Playgroud)
您还可以if通过简单地使用以下内容来缩短零件:
$nav.toggleClass("doch", $(this).scrollTop() > winH );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13521 次 |
| 最近记录: |