任何想法如何将100px转换为100vw?
$(document).ready(function(){
$(window).scroll(function() {
if ($(document).scrollTop() > 100) {
$(".header").css("color", "#fff");
} else {
$(".header").css("color", "#000");
}
});
});
您可以通过此行代码获得视口宽度:
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);