Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delay Jquery UIBlock Plugin?

I am using this plugin. http://jquery.malsup.com/block/#overview

However I would like this blockUI to only show up say if the ajax request goes more than 1second. If no show nothing.

Is there a way I can do this?

like image 696
chobo2 Avatar asked Aug 17 '10 21:08

chobo2


1 Answers

When you call your AJAX, call the BlockUI in a setTimeout().

    // Using a setTimeout, display the blockUI after 1000 milliseconds
var timeout = setTimeout(function() {
    $.blockUI({ message: $('selector') }); 
}, 1000);

$.ajax({
    url:'/some/path',
    success: function( data ) {
        // your success callback
    },
    complete: function() {
           // Clear the timeout just in case the response came back
           //   in less than 1000 milliseconds
        clearTimeout(timeout);
        $.unblockUI();
    }
});
like image 73
user113716 Avatar answered Sep 18 '22 22:09

user113716