Rui
Rui

Reputation: 39

Javascript fadeIn() transition

I have this code that switches the opacity of an image after a certain delay:

$(".pattern-overlay").css("background","black").delay(2000).queue(function() {
    $(this).css("background", "rgba(0, 0, 0, 0.4)").dequeue();
});

How can I make the transition look smooth instead of just switching the colors directly?

Upvotes: 0

Views: 38

Answers (2)

Fuross
Fuross

Reputation: 518

Here is a working example with animate():

$(".pattern-overlay").css("background","black").delay(2000).animate({
    opacity: 0.4,
}, 1000);
.pattern-overlay {
    width: 200px;
    height: 200px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="pattern-overlay"></div>

Upvotes: 1

Abdullah Tellioglu
Abdullah Tellioglu

Reputation: 1474

You can use hide function in Jquery with timeout. You can checkout this page for hiding of your DOM elements with animation. http://api.jquery.com/hide/
Sample Code :

$("#yourElementId").hide("slow");

Upvotes: 0

Related Questions