[英]Sticky top bar rendering issue in Chrome
Let me cut to the chase. 让我开始追逐。 It's on this site: http://www.smb.nu/wip/kampanj/
在此网站上: http : //www.smb.nu/wip/kampanj/
The white bar with the links is supposed to stick to the top when scrolled past, this effect is achieved with some simple jQuery: 滚动链接时,带有链接的白条应该停留在顶部,这种效果可以通过一些简单的jQuery来实现:
$(window).scroll(function() {
$('#floater').toggleClass('sticky', $(window).scrollTop() > 129);
$('#quote').toggleClass('sticky', $(window).scrollTop() > 129);
});
So far, so good (I believe). 到目前为止,一切都很好(我相信)。 The css classes look like so:
CSS类如下所示:
#floater.sticky {
position: fixed;
top: 0;
z-index: 2;
}
div#quote.sticky {
padding-top: 78px;
}
This works just fine in Firefox (OS X and Windows), and even in IE (gasp!). 这在Firefox(OS X和Windows)甚至IE(gasp!)中都可以正常工作。 However, in Chrome (OS X and Windows) as well as Safari (OS X), it flickers, disappears and reappears, every so often.
但是,在Chrome(OS X和Windows)以及Safari(OS X)中,它经常闪烁,消失并重新出现。 This despite Chrome's web inspector telling me it's there ( screenshot ).
尽管Chrome的网络检查人员告诉我它在那里( 屏幕截图 ),但这仍然没有。
What the hell is going on? 这到底是怎么回事? Did I stumble upon a WebKit rendering bug with fixed positioning (seems highly unlikely), or make some basic beginner's mistake?
我是偶然发现了固定位置的WebKit渲染错误(似乎极不可能),还是犯了一些基本的初学者错误? Or is it something else entirely?
还是完全其他?
Adding: 添加:
-webkit-backface-visibility:hidden
to the parent container should do the trick. 到父容器应该可以解决问题。
I fixed it with -webkit-transform: translateZ(0);
我用
-webkit-transform: translateZ(0);
修复了它-webkit-transform: translateZ(0);
on chrome's console... Don't ask me why, I think it triggers some gpu's calculation and seems to fix it. 在chrome的控制台上...不要问我为什么,我认为它会触发某些GPU的计算,并且似乎可以解决该问题。 But that's a dirty workaround wich may breaks in a near future.
但这是一个肮脏的解决方法,在不久的将来可能会中断。
When you remove the -webkit-filter: blur(0px); 当您删除-webkit-filter时:blur(0px); off of #uberwrapper the header functions correctly.
#uberwrapper的标头功能正常。
This can be achieved by using pure css, why you need jquery? 这可以通过使用纯CSS实现,为什么需要jquery?
http://jsfiddle.net/SRpA4/ http://jsfiddle.net/SRpA4/
.header-cont {
width:100%;
position:fixed;
top:0px;
height:50px;
background-color:#C00;
} }
I think chrome may have made a change recently to the way it renders position:fixed. 我认为chrome最近可能已经改变了它的位置呈现方式:固定。 I haven't got a clue what they've done or why it's not working for you corrently, but I do have a solution that is probably better because it will work on mobiles too (many mobiles don't support fixed positioning).
我不知道他们做了什么,或者为什么它不适当地为您服务,但我确实有一个更好的解决方案,因为它也可以在手机上使用(许多手机不支持固定定位)。
jQuery jQuery的
$(window).scroll(function() {
if ( $(window).scrollTop() > 129 ) {
var scrollTop = $(window).scrollTop();
$('#floater').addClass('sticky').css('top',scrollTop);
}
else { $('#floater').removeClass('sticky'); }
});
CSS CSS
#floater.sticky {
position: absolute;
top: 0;
z-index: 2; }
That seems to be a bug. 那似乎是一个错误。 The
-webkit-filter: blur(0px);
-webkit-filter: blur(0px);
for #uberwrapper seems to be causing the issue. 因为#uberwrapper似乎是造成此问题的原因。
Dont know the exact reason behind it. 不知道其背后的确切原因。 But an easy fix would be to Remove
-webkit-filter: blur(0px);
但是一个简单的解决方法是删除
-webkit-filter: blur(0px);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.