首页 > 解决方案 > 当窗口中存在轻微滚动时,标题粘性会闪烁

问题描述

在我的网站中,我正在制作标题以使其保持粘性,但唯一的问题是如果我的窗口有轻微滚动并且我没有任何数据,那么页面会闪烁,或者直到数据没有被加载然后它会闪烁。有人可以帮我吗?

     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");
        }
      }

标签: javascriptjquery

解决方案


推荐阅读