开发者

How to make it so events cannot occur while an event is running in DOJO?

Is there some way I can disable开发者_如何转开发 all events until an event is completed in DOJO? For instance I am fading elements and the user can click the event again and it will not complete the last event.


If you control all events that need to be disabled, you could try using a global variable as a "lock" - set it on when you start the animation (and have all events abort if they find this flag triggered) and unset it when it ends.

Javascript is not concurrent (so you don't need to worry about timing issues and having an "actual" lock) but perhaps the fading uses setTimeout behind the scenes (allowing other events to trigger before it is done). If this is the case, just remember that you would need to use the onEnd callback to properly detect when the anim is over

var lock = false;
function my_event_handler(evt){
    if(lock) return; //someone else is using the lock; 
    //perhaps cancel event propagation as well?

    lock = true;

    dojo.anim({
        ...
        onEnd: function(){
            lock = false;
        }
    });
}

caveat: this is pseudocode off the top of my head. I haven't used dojo animations in a while if you didn't notice already :P


I'm not sure I understand what you mean by events here, but if you want to prevent interaction with elements on a page, you can put up a modal shield... basically a transparent DIV element to capture events, positioned over your content with a high z-index

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜