javascript - 当窗口中存在轻微滚动时,标题粘性会闪烁
问题描述
在我的网站中,我正在制作标题以使其保持粘性,但唯一的问题是如果我的窗口有轻微滚动并且我没有任何数据,那么页面会闪烁,或者直到数据没有被加载然后它会闪烁。有人可以帮我吗?
window.onscroll = function() {stickyHeader()};
function stickyHeader() {
var header = document.getElementById("CC-wr-headerWidget")
if(!document.getElementById("CC-wr-headerWidget")){
return;
}
var sticky = 100;
if (window.pageYOffset > sticky) {
$('.promobar-1').css('opacity', 0);
header.classList.add("state-collapsed");
} else {
$('.promobar-1').css('opacity', 1);
header.classList.remove("state-collapsed");
header.classList.remove("state-not-collapsed");
}
}
解决方案
推荐阅读
- laravel - Laravel dispatch a Job after finishing the Job racks up memory and then fails
- javascript - reactjs - 如何在react.JS中将子窗口url放入父窗口?
- android - 如何在数字选项卡上启动 EditText(Xamarin.Forms 条目)?
- firebase - 将用户数据保存到 Firestore
- r - How can I dynamically select columns of imported shapefile for further analysis in R Shiny?
- firebase - Firebase SSE (server-sent events) REST. Monitor + Write on same connection
- javascript - 使用 React JS 在地图中显示带有 xy 坐标的标记
- java - Is there any other way to fill this array as needed
- java - 如何测试使用休眠将对象保存到数据库的方法?
- node.js - React - 发布为 npm 包的组件之间的通信和路由