Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery fadeIn and fadeOut lag in chrome but not in Firefox

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!

like image 946
Qub1 Avatar asked Apr 30 '14 19:04

Qub1


1 Answers

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.

like image 101
Tarun Avatar answered Oct 16 '22 13:10

Tarun