jquery blockUI tell if page or specific element is

2019-04-04 08:57发布

Is there a way to tell if $.blockUI(); has been called but $.unblockUI() has not been called? Ideally this should be able to work for both blocking the full page and specific elements.

I'd expect it to work something like this

> $.blockUI();
> $.isBlockUI?():
>> true
> $.unblockUI();
> $.isBlockUI?();
>> false

3条回答
Anthone
2楼-- · 2019-04-04 09:19

Look what I found here

  $(document).ready(function() { 
    $('#demo14').click(function() { 
        $.blockUI({ 
            fadeIn: 1000, 
            timeout:   2000, 
            onBlock: function() { 
                alert('Page is now blocked; fadeIn complete'); 
            } 
        }); 
    });

Evidently there's one for Block and unBlock sorta like a onSuccess function. So on the onBlock function you'd simply just set a global boolean value.

Hope this helps!

Happy Coding! ;)

查看更多
▲ chillily
3楼-- · 2019-04-04 09:30
var data = $('#element').data();
//will return Object like: { blockUI.isBlocked=1, blockUI.onUnblock=null} 

if (data["blockUI.isBlocked"] == 1)
// is blocked
else
// is not blocked
查看更多
ゆ 、 Hurt°
4楼-- · 2019-04-04 09:37

I use a more primitive hack :

var isUIBlocked = $('.ui-widget-overlay:visible').length > 0;

if(isUIBlocked){
  // something is displayed with an active overlay, hence stop
}

This works for me even when using .dialog() with modal:true

查看更多
登录 后发表回答