TaylorMac
TaylorMac

Reputation: 9002

Jquery .addclass 'Duration' Not working even with Google Labs script?

The jQuery .addclass function is working well to add classes, but they do not come in on a duration:

    jQuery(document).ready(function(){

newdiv = $('<div id=\'id".$row_new['ID']."\' style=\"display:none;\" class=\"eventdiv\" data-sort=\"" . $row_new['TimeStamp'] . "\">" . $row_new['Title'] . " TIME: " . $row_new['TimeStamp'] . "</div>');

    $('[data-sort=".$after."]').after(newdiv);

    $('#id".$row_new['ID']."').slideDown('slow', function() {                                                                                   
        $(this).addClass('gradient shadow curved_sml', 5000);
    });

    });

The code is escaped because it is returned as an object from a php page (through an ajax request) to an html page.

I have tried all different versions of JqueryUI and Jquery, none of them seem to allow it to add a duration to .addclass, the 5000 just becomes a delay.

Currently I have JqueryUI 1.8.9 and Jquery 1.5.2 installed because those versions seem to perform the duration in JSfiddle, but not on my page..

Upvotes: 2

Views: 1432

Answers (1)

Matt
Matt

Reputation: 75317

EDIT: I take some of this back... jQuery UI does accept a duration as the second parameter of addClass. jQuery itself does not accept a duration as the second parameter. The second parameter in jQuery UI is how long the effects of adding the class should last for; if you want to delay the addition of the class, then my answer still works.


addClass does not accept a delay as the second parameter.

If you want the class to be added 5 seconds after the slideDown has completed, use setTimeout:

 $('#id".$row_new['ID']."').slideDown('slow', function() {
    var that = this;                                                                                   
    setTimeout(function () {
        $(that).addClass('gradient shadow curved_sml');
    }, 5000);
 });

If you want the slideDown to take 5 seconds, and the class's to be added immediately:

$('#id".$row_new['ID']."').slideDown(5000, function() {
    $(this).addClass('gradient shadow curved_sml');
});

Upvotes: 2

Related Questions