javascript - Overlay div doesn't prevent the next event that fired in a specific time window -
In my application, I add a The loader is displayed if the user forces a JS: ; Div id = "overlay" class = "loadmask" onclick: "return false;" & Gt; Div class = "removeDiv" onclick = "sleep (3000)" & gt; & Lt; Span & gt; Click to remove overlay after 3 seconds & lt; / Span & gt; & Lt; / Div & gt; & Lt; / Div & gt; '); $ ('Body') attached (maskDiv). } Function removeDiv () {$ ("# overlay"). Remove (); } Function sleep (milliseconds) {var start = new date () GetTime (); For (var i = 0; i & lt; 1e7; i ++) {if ((new date). GetTime () - start) & gt; Milliseconds {break; }} RemoveDiv (); } How can I solve this problem? Resolve this problem Align the Strange 'sleeping' function Do you exist there? Why do not you use internal timeouts: loaderDiv to avoid all userevents on the page.
clickevent (like a green container onclick), the event is removed after the loader divis disappears.
function append overlay () {var maskediv = $ ('& lt)
setTimeout (removeDiv (), 0) . This is a problem with javascript event loop execution.
removeDiv () on the next tick and the userEvent
onClick () is executed first.
function sleep (milliseconds) {setTimeout (function () {removeDiv ();}, milliseconds); }
Comments
Post a Comment