I have an overlay that should appear on top of everything by fading in after the user clicks on a button. I'm using jQuery fadeIn and fadeOut for this. However, there is significant lag in chrome while doing so, while in Firefox the animations run smooth.
Here's my HTML:
<div class="overlay">
<div class="overlay_profile">
<div class="overlay_contents">
<div class="overlay_profile_info">
<img src="images/avatars/1.gif" />
<div class="overlay_profile_info_text_username">
Qub1
</div>
<div class="overlay_profile_info_text_other">
Level 1
</div>
</div>
</div>
</div>
<div class="overlay_close">X</div>
</div>
<div class="overlay_shadow"></div>
And my CSS:
.overlay {
display: none;
padding: 20px;
position: fixed;
top: 150px;
right: 150px;
bottom: 100px;
left: 150px;
z-index: 2;
background: #978470;
border: 3px solid #CCC;
border-radius: 20px;
box-shadow: 0 0 20px #000, inset 0 0 10px #6A5C4E;
}
.overlay_shadow {
display: none;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1;
background: rgba(0, 0, 0, 0.5);
}
And JavaScript:
$(document).ready(function(){
$(".menu_arrow").add(".overlay_close").add(".overlay_shadow").click(function() {
if($(".overlay").is(':visible')) {
$(".overlay").add(".overlay_shadow").fadeOut("normal");
} else {
$(".overlay").add(".overlay_shadow").fadeIn("normal");
}
});
});
Does anyone have an idea why chrome would be lagging? Is it the heavy use of CSS3?
Any help is appreciated!
Try adding these rules to your classes:
{
-webkit-transform: translatez(0);
-moz-transform: translatez(0);
-ms-transform: translatez(0);
-o-transform: translatez(0);
transform: translatez(0);
}
This forces/tricks Chrome to send the CSS3 operations to the GPU, which should speed it up.
I guess it's just because Chrome is a bit shy about what it transfers to the GPU unlike Firefox.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With