简体   繁体   English

标头所在位置:收缩时粘性在铬中闪烁

[英]Header with position:sticky is flickering in chrome when shrinking

I have a navigation element , below some other content, that I should be fixed , as soon as the scroll height is reached. 我有一个导航元素 ,在其他一些内容下,一旦达到滚动高度,就应该对其进行fixed This is achieved with position:sticky and works fine in all browsers. 这是通过position:sticky实现的,并且在所有浏览器中都可以正常工作。 But I also want to shrink that element as soon as it is fixed. 但是,我也想在该元素固定后立即缩小它。

https://codepen.io/arichter83/pen/xMLyOJ https://codepen.io/arichter83/pen/xMLyOJ

If scrolled slowly at Chrome (71.0.3578.98 64-bit Mac) this header flickers, because if the element is shrinking, the window.scrollY of the page is reduced, which makes the element become larger again... back and forth. 如果在Chrome浏览器 (71.0.3578.98 64位Mac)上缓慢滚动 ,则此标题会闪烁,因为如果元素正在收缩,则页面的window.scrollY会减小,这会使元素再次变大...来回。 (use "start" to see the behavior) (使用“开始”查看行为)

Any workaround for this? 任何解决方法?

  • Wrapping in fixed height: this would stop the content below to move upwards, which I want. 包装成固定的高度:这会阻止下面的内容向上移动,这是我想要的。

Adding a position property to your header.minified ID seems to have stopped the flickering. 在您的header.minified ID中添加位置属性似乎已停止闪烁。

 #header.minified {
        font-size: 24px;
        line-height: 48px;
        height: 48px;
        background: #efc47D;
        text-align: left;
        padding-left: 20px;
        position: fixed;

 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM