Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent CSS pseudo elements from disappearing during an animation?

Here is my (simplified) situation:

http://jsfiddle.net/qFhaq/

Clicking the button launches an animation that expands the height of the div. While the div is expanding, the :after pseudo-element (containing the text 'look') disappears and then reappears at the end of the animation.

Is there a way to prevent the pseudo-element from disappearing, so that it's visible throughout the animation?

like image 926
Daniel Avatar asked Jul 20 '13 21:07

Daniel


2 Answers

Add "overflow" CSS rule to #main and set it to "visible !important;"

#main{
    width: 200px;
    height: 200px;
    background-color: #eee;
    border: 1px solid black;
    overflow:visible !important;
}
like image 190
aljordan82 Avatar answered Sep 24 '22 19:09

aljordan82


I rewrite it that it used CSS3 transition:

JS (for fast, for better you can change it to vanilla js):

$(function(){
    $("#clicky").click(function(){
        $("#main").addClass('animate');
    });
});

CSS:

#main{
    width: 200px;
    height: 200px;
    background-color: #eee;
    border: 1px solid black;
    -webkit-transition: height 2s linear;
}

#main:after{
    content: "look";
    height: 50px;
    background-color: white;
    margin-left: 210px;
    border: 1px solid black;
}

#main.animate{
    height: 500px;
}

http://jsfiddle.net/qFhaq/1/

like image 25
WooCaSh Avatar answered Sep 23 '22 19:09

WooCaSh