Charlie
Charlie

Reputation: 11787

Run BlockUI on page load?

How can I run the BlockUI plugin (http://www.malsup.com/jquery/block/#demos) when the page loads? I modified it so that when you click the body tag it runs the plugin, but I want that to happen when the page loads...

<script type="text/javascript" language="javascript">
$(document).ready(function() { 
    $('body').click(function() {
        $.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .5, 
            color: '#fff' 
        } }); 

        setTimeout($.unblockUI, 2000); 
    }); 
}); 
</script>

Upvotes: 0

Views: 5876

Answers (2)

genesis
genesis

Reputation: 50976

take it out from that click event (or copy-paste (or use function - the best one))

<script type="text/javascript" language="javascript">
$(document).ready(function() { 
    $.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .5, 
            color: '#fff' 
    } }); 
    setTimeout($.unblockUI, 2000);
    $('body').click(function() {
        $.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .5, 
            color: '#fff' 
        } });  
        setTimeout($.unblockUI, 2000);
    }); 
}); 
</script>

Upvotes: 1

Joe
Joe

Reputation: 15802

Just take it out of the click method.

$(document).ready(function() {
    blockUI({ parameters });
    setTimeout...
    $('body').click...
}

Upvotes: 2

Related Questions