你知道怎么把100px转换成100vw吗?
$(document).ready(function(){
$(window).scroll(function() {
if ($(document).scrollTop() > 100) {
$(".header").css("color", "#fff");
} else {
$(".header").css("color", "#000");
}
});
});发布于 2020-06-09 23:49:05
您可以使用下面这行代码来获取视口宽度:
const width = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);然后在代码中使用该变量,如下例所示:
$(document).ready(function(){
const width = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
$(window).scroll(function() {
if ($(document).scrollTop() > width) {
$(".header").css("color", "#fff");
} else {
$(".header").css("color", "#000");
}
});
});请注意,您引用的是scrollTop,因此您可能想要获取vh,在本例中,您可以使用以下另一行代码:
const height = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0);https://stackoverflow.com/questions/62286459
复制相似问题