unemployment Posted February 18, 2011 Share Posted February 18, 2011 This function fails. I want to set the onmouseout to have a delay of 500 milliseconds comp_list.onmouseout = window.setTimeout(function (){ if (hasClass(comp_list, 'block')) { removeClass(comp_list, 'block'); removeClass(comp_drop, 'active'); } }, 500); Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/ Share on other sites More sharing options...
jcanker Posted February 18, 2011 Share Posted February 18, 2011 Define "fails." Does it throw an error? Does it not wait? Does it wait too long? What is it doing that it shouldn't, or not doing that it should? Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1175984 Share on other sites More sharing options...
unemployment Posted February 18, 2011 Author Share Posted February 18, 2011 Define "fails." Does it throw an error? Does it not wait? Does it wait too long? What is it doing that it shouldn't, or not doing that it should? It does not remove the classes nor does it seem to be issuing the millisecond delay. Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1175987 Share on other sites More sharing options...
jcanker Posted February 18, 2011 Share Posted February 18, 2011 Have you tried with an alert to ensure that you're entering the loop in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1175988 Share on other sites More sharing options...
unemployment Posted February 18, 2011 Author Share Posted February 18, 2011 Have you tried with an alert to ensure that you're entering the loop in the first place? My alert doesn't issue an error, plus... my text editor doesn't like the syntax so it must be a syntax error. Any other way to write this? Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1175990 Share on other sites More sharing options...
jcanker Posted February 18, 2011 Share Posted February 18, 2011 No, what I meant was to use the alert() function inside the if statement to notify you when you're entering the condition. If you're getting a syntax error, that would be it, but it could be a missed closing quote, parenthetical, semicolon, etc earlier in the code. This particular snippet shows up fine in ExpressionWeb 4 without any syntax error. If your editor is color-coded then you can get a better gauge as to where it goes off the rails. Change your code to: comp_list.onmouseout = window.setTimeout(function (){ if (hasClass(comp_list, 'block')) { alert("We're entering into the if hasClass statement"); removeClass(comp_list, 'block'); removeClass(comp_drop, 'active'); } }, 500); That will let you know whether it if statement is evaluating to true and entering the conditional or not. When it's working, just remove the alert() statement. Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1175992 Share on other sites More sharing options...
unemployment Posted February 18, 2011 Author Share Posted February 18, 2011 No, what I meant was to use the alert() function inside the if statement to notify you when you're entering the condition. If you're getting a syntax error, that would be it, but it could be a missed closing quote, parenthetical, semicolon, etc earlier in the code. This particular snippet shows up fine in ExpressionWeb 4 without any syntax error. If your editor is color-coded then you can get a better gauge as to where it goes off the rails. Change your code to: comp_list.onmouseout = window.setTimeout(function (){ if (hasClass(comp_list, 'block')) { alert("We're entering into the if hasClass statement"); removeClass(comp_list, 'block'); removeClass(comp_drop, 'active'); } }, 500); That will let you know whether it if statement is evaluating to true and entering the conditional or not. When it's working, just remove the alert() statement. the if is not issuing the alert. Below is my entire script which only breaks on the onmouseout event. The commented onmouseout event works, but it just does not have the delay. addOnload(function() { var comp_drop = document.getElementById('comp_drop'); var comp_list = document.getElementById('comp_list'); comp_drop.onclick = function (){ if (hasClass(this, 'active')) { removeClass(this, 'active'); removeClass(comp_list, 'block'); } else { addClass(this, 'active'); addClass(comp_list, 'block'); } return false } comp_drop.onmouseover = function (){ if (!hasClass(this, 'active')) { addClass(this, 'active'); addClass(comp_list, 'block'); } } comp_list.onmouseover = function (){ if (!hasClass(this, 'block')) { addClass(this, 'block'); addClass(comp_drop, 'active'); } } comp_list.onmouseout = window.setTimeout(function (){ if (hasClass(comp_list, 'block')) { alert("We're entering into the if hasClass statement"); removeClass(comp_list, 'block'); removeClass(comp_drop, 'active'); } }, 500); //comp_list.onmouseout =function (){ // if (hasClass(comp_list, 'block')) // { // removeClass(comp_list, 'block'); // removeClass(comp_drop, 'active'); // } //} }); Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1175994 Share on other sites More sharing options...
jcanker Posted February 18, 2011 Share Posted February 18, 2011 Earlier you said it wasn't removing the classes. Is it removing the classes or not? Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1176013 Share on other sites More sharing options...
unemployment Posted February 18, 2011 Author Share Posted February 18, 2011 Earlier you said it wasn't removing the classes. Is it removing the classes or not? No the onmouseout is not removing the class. Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1176065 Share on other sites More sharing options...
jcanker Posted February 18, 2011 Share Posted February 18, 2011 Below is my entire script which only breaks on the onmouseout event. The commented onmouseout event works, but it just does not have the delay. No the onmouseout is not removing the class. Please understand, I'm trying hard to help you, but you have to help me help you, which includes being clear about symptoms and willing to follow troubleshooting advice. With your code, if it's not removing the classes, then it's probably not entering that portion of the if/else statement. PLEASE PLACE AN ALERT() STATEMENT IN THE IF EVALUATION BLOCK AS I REQUESTED EARLIER. Run the code and test the mouse out behavior. If you get the alert window popping up with the coded message and it's still not removing the classes, that's a completely different symptom. First we have to ensure that it's entering the IF block. Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1176227 Share on other sites More sharing options...
unemployment Posted February 18, 2011 Author Share Posted February 18, 2011 Below is my entire script which only breaks on the onmouseout event. The commented onmouseout event works, but it just does not have the delay. No the onmouseout is not removing the class. Please understand, I'm trying hard to help you, but you have to help me help you, which includes being clear about symptoms and willing to follow troubleshooting advice. With your code, if it's not removing the classes, then it's probably not entering that portion of the if/else statement. PLEASE PLACE AN ALERT() STATEMENT IN THE IF EVALUATION BLOCK AS I REQUESTED EARLIER. Run the code and test the mouse out behavior. If you get the alert window popping up with the coded message and it's still not removing the classes, that's a completely different symptom. First we have to ensure that it's entering the IF block. Well I almost fixed the issue. Review the code below. I now have different issue. First, this function is for a drop down and when you leave the drop down I want a 500 millisecond delay. The problem I am now having is that the function executes while I am still hovered over the drop down. I only want the timer to start after I leave the drop down list. As a result, my alert should only execute when I leave the drop down. (The alert will be removed once it is working) comp_list.onmouseout=function(){ setTimeout(function (){ alert("function entered") if (hasClass(comp_list, 'block')) { alert("hasClass satisified") removeClass(comp_list, 'block'); removeClass(comp_drop, 'active'); } }, 3500); } Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1176232 Share on other sites More sharing options...
KevinM1 Posted February 18, 2011 Share Posted February 18, 2011 EDIT: What element is comp_list? And what's its relationship to comp_drop? I'm thinking there's an event bubbling issue at play here. Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1176239 Share on other sites More sharing options...
unemployment Posted February 18, 2011 Author Share Posted February 18, 2011 EDIT: What element is comp_list? And what's its relationship to comp_drop? I'm thinking there's an event bubbling issue at play here. comp_drop is the drop down arrow and comp_list is the info in the drop down menu. HTML is below <li class="marr"> <a href="../clng.php">Company Settings<div id="comp_drop" class="menu_arr_down">▼</div></a> <dl id="comp_list"> <dt></dt> <dd class="bbs"><a href="clanding.php">Show all</a></dd> <dd class="first"><a href="../csings.php?c=ign">ign</a></dd> <dd class="last"><a href="../csings.php?c=pr">Pr</a></dd> </dl> </li> Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1176264 Share on other sites More sharing options...
KevinM1 Posted February 18, 2011 Share Posted February 18, 2011 When you say 'hovered over the drop down', do you mean the mouseout effect is running when you're still hovering on comp_list, or comp_drop? Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1176268 Share on other sites More sharing options...
unemployment Posted February 18, 2011 Author Share Posted February 18, 2011 When you say 'hovered over the drop down', do you mean the mouseout effect is running when you're still hovering on comp_list, or comp_drop? Yes, it runs when I am still hovering / mousingover comp_list Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1176278 Share on other sites More sharing options...
KevinM1 Posted February 18, 2011 Share Posted February 18, 2011 Hmm... it could be, like I said before, an event bubbling issue. http://www.quirksmode.org/js/events_order.html Quote Link to comment https://forums.phpfreaks.com/topic/228056-broken-onmouseout/#findComment-1176281 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.