如何在 .scrolltop 函数中使用 vh 单位而不是像素 [英] how to use vh units instead of pixels for .scrolltop functions

查看:139
本文介绍了如何在 .scrolltop 函数中使用 vh 单位而不是像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个菜单栏,我想在用户滚动到下一个 div 后更改其类别,该 div 高 100vh.下面的功能仅适用于我的尺寸的屏幕,任何较小或较大的动画都会过早或过晚.

I have a menu bar who's class I want to change after a users scrolls to the next div, the div is 100vh tall. The function below works only with screens my size, anything smaller or bigger the animation will go to early or too late.

如何制作此函数使用的单位 vh?谢谢

How do I make the units that this function uses vh? Thanks

  $(window).scroll(function() {    
var scroll = $(window).scrollTop();
if (scroll >= 600) {   <---- change to vh units not px-----
    $(".home").removeClass("open");
}

推荐答案

100vh 是该屏幕的实际视图高度.所以当你使用不同尺寸的屏幕时,100vh 将被计算为不同的尺寸.

100vh is the actual view height of that screen. so when you use different size screens 100vh will be calculated to a different size.

这篇关于如何在 .scrolltop 函数中使用 vh 单位而不是像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆