Reputation: 4708
I'm trying to solve a bug that includes a user opening a menu and when they enter Div1, Div2 or Div3 the menu closes and my code gets executed. The test();
function is supposed to run the code, unless the HMAnimState
variable is true (or the login, which isn't really the case here).
Right now what happens is when they enter the selected divs and they do it while one of my animations is still running, the HMAnimState
variable is set to true, and after that it can't see if the user enters the div since it needs a sort of reload, since if that doesn't happen the screen stays stuck on the same position.
I tried doing this by using
setTimeout(function(){ test().mouseleave().mouseenter(); }, 1000);
But this doesn't work.
Moving from the div the user is hovering over to one of the other 2 divs works but it's quite impractical.
$(".Div1, #Div2, #Div3").mouseenter(function test(){
if (HMAnimState === true || HMAnimState === "LoginOverride") {
//Loop until HMAnimState is false
setTimeout(function(){ test().mouseleave().mouseenter(); }, 1000);
return false;
}else{
// Hide div1 and other stuff
}
});
Upvotes: 0
Views: 38
Reputation: 411
I think a bit more detail might be useful, but from what I understand perhaps the following would work.
Whenever your event fires and HMAnimState is true, push the request onto an array. Then, when HMAnimState is set to false, loop over the pending requests and execute them. This assumes that you have an event listener somewhere and you know when HMAnimState is set to false.
Here is a sample of this idea, I have not actually tested this.
var stack = [];
$(".Div1, #Div2, #Div3").mouseenter(function test(){
if (HMAnimState === true || HMAnimState === "LoginOverride") {
//push any metadata about this event you will need in order to execute
//this request later onto the stack
stack.push("div_mouseenter", this);
return false;
}else{
// Hide div1 and other stuff
}
});
//just a sample function I assume you have access to
function onAnimationComplete() {
HMAnimState = false;
for(var i = 0; i < stack.length; ++i) {
handleRequest(stack[i]);
}
}
Upvotes: 1