Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to fade in newly created elements using only css3?

I am working with a chat script. I have no control over any javascript, only CSS. I was wondering if it is possible to get the posts to fade in, as they are added, with only CSS3.

Here is a simplified example of the chat script:

http://jsfiddle.net/CF4pj/1/

<a class="click" href="#/">click</a>

<div class="stuff"></div>

<script>

$("a.click").click(function() {
    $("div.stuff").append("<div class='lol'>text text text text text</div>");
});

</script>

Is there any CSS3 (only CSS3, no javascript) I could add to the script above to make the new "posts" fade in?

like image 236
supercoolville Avatar asked Oct 01 '13 05:10

supercoolville


People also ask

How do I fade out an element in CSS?

In the CSS, use the @keyframes rule paired with fadeIn. At 0%, set the opacity to 0. At 100%, set the opacity to 1. This creates the fade-in effect.

How do you make a div appear slowly CSS?

$("div"). animate({ opacity:0 },"slow"); This is useful if you also want to animate other properties of the element at the same time.

What is fade in animation?

In android, Fade In and Fade Out animations are used to change the appearance and behavior of the objects over a particular interval of time. The Fade In and Fade Out animations will provide a better look and feel for our applications.


1 Answers

Here you go...

div.click {
    background:yellow;
    display:inline;
}
div.lol {
    padding:5px;
    border:1px solid green;
    margin:5px 0;
    animation: fadein 2s;
    -moz-animation: fadein 2s;
    /* Firefox */
    -webkit-animation: fadein 2s;
    /* Safari and Chrome */
    -o-animation: fadein 2s;
    /* Opera */
}
@keyframes fadein {
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-moz-keyframes fadein {
    /* Firefox */
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-webkit-keyframes fadein {
    /* Safari and Chrome */
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-o-keyframes fadein {
    /* Opera */
    from {
        opacity:0;
    }
    to {
        opacity: 1;
    }
}

Check out this fiddle...jsfiddle

like image 165
nik Avatar answered Oct 17 '22 08:10

nik