0

I've got a problem executing functions sequentially. On my html file I've got this:

<body onload="start();">

    <div id="title"><div id="welcome">WELCOME</div></div>

Inside my JS I've got this, which should execute the background change to black, and when that ended it would make the "welcome" div appear.

function start(){

    $('body').css('background', 'black', function() {
        $('#welcome').fadeIn("slow");
    });

}

Problem is: Only the background change is being executed. I get no errors on the browser console.

Any ideas on where I might have gone wrong?

EDIT: I've got this on the body css so that it slowly changes from white to black

-webkit-transition:all 1.0s ease;
    -moz-transition:all 1.0s ease;
    transition:all 1.0s ease;
1

4 Answers 4

2

Where in the documentation do you see that function signature? That does not exist.

.css( propertyName )
.css( propertyNames )
.css( propertyName, value)
.css( propertyName, function(index, value) )
.css( properties )

Break it up, there is no callback that executes. It is not an asynchronous step.

$('body').css('background', 'black');
$('#welcome').fadeIn("slow");
Sign up to request clarification or add additional context in comments.

2 Comments

Thing is: how can I change the duration of the background change?
css() is not animate()
0

Why not update each function in one line?

function start() { // rename this..
  $('body').css('background', 'black');
  $('#welcome').fadeIn();
}

Comments

0

Try this.. may be helpful to you.

$('body').css('background', 'black');
$('#welcome').fadeIn("slow");

Comments

0

jQuery css() doesn't have a callback - I think you confuse it with "animate" which is a slow (therefore a delayed) thing to do while "css" happens immediately.

You can chain jQuery commands like this:

$(".stuff").css("background","black").css("color","red")

This can be done with anything that happens immediately. Callbacks are for proper timing when something takes time.

Also, for css, there is another way:

$(".stuff").css({
    "background":"black",
    "color":"red",
});

But that's not very general in jQuery. Chaining (like above) will work almost everywhere.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.