Is there a jQuery mouse event for entering an element from outside only? by SINep - TribalWar Forums
Click Here to find great hosting deals from Branzone.com


Go Back   TribalWar Forums > TribalWar Community > General Discussion
Reload this Page Is there a jQuery mouse event for entering an element from outside only?
Thread Tools
SINep
VeteranX
Old
1 - 03-24-2012, 06:24 PM
Reply With Quote
i.e. Not just entering it from when a page changes, and the element is in the same position as your mouse was from the page before it?

Using mouseenter or mouseover causes unintentional double plays.
 
SINep is offline
 
Sponsored Links
SINep
VeteranX
Old
2 - 03-24-2012, 06:37 PM
Reply With Quote
Sigh.
 
SINep is offline
 
Pachacutec
VeteranX
Old
3 - 03-24-2012, 06:37 PM
Reply With Quote
does this look like mutha****in stackoverflow to you biatch!?!?!
 
Pachacutec is offline
 
caelum
VeteranX
Contributor
Old
4 - 03-24-2012, 06:38 PM
Reply With Quote
 
caelum is offline
 
Breyer
VeteranX
Contributor
Old
5 - 03-24-2012, 06:41 PM
Reply With Quote
Well at least we know it's possible
 
Breyer is offline
 
SINep
VeteranX
Old
6 - 03-24-2012, 07:02 PM
Reply With Quote
Hrmph.
 
SINep is offline
 
broast
Veteran
Old
7 - 03-24-2012, 07:05 PM
Reply With Quote
i would just use a boolean switch telling me when its outside, default to false on init, set to true on mouse leave, or set to true on enter of a surrounding element, and then on mouse enter check if true, do your thing and then reset to false

that is, if im understanding you correctly
 
broast is offline
 
Last edited by broast; 03-24-2012 at 08:00 PM.
SINep
VeteranX
Old
8 - 03-24-2012, 07:20 PM
Reply With Quote
Quote:
Originally Posted by broast View Post
i would just use a boolean switch telling me when its outside, default to false on init, set to true on mouse leave, or set to false on enter of a surrounding element, and then on mouse enter check if true, do your thing and then reset to false

that is, if im understanding you correctly
I don't know jQuery/Javascript much, just roping my way through it with tuts.

It would actually need to default to false if already inside, and not retrigger on mouseleave. Basically trying to get it how it is right now, but to disable the retrigger when it's already inside the element. i.e., the page loads, your mouse is in the same position, and so is the same element.

This is what I currently have
Code:
<ul id="nav2" class="tabs">
<li><a href=""<?php if ($currentPage=="page1") echo ' class="on"'; ?>>Page1</a>
	<audio id="beep-two0" preload="auto"><source src="_audio/beep.mp3" /><source src="_audio/beep.ogg" /></audio></li>
<li><a href=""<?php if ($currentPage=="page2") echo ' class="on"'; ?>>Page2</a>
	<audio id="beep-two1" preload="auto"><source src="_audio/beep.mp3" /><source src="_audio/beep.ogg" /></audio></li>
</ul>

<script>
		$("#nav2 a")
		  .each(function(i) {
			 if (i != 0) { 
				$("#beep-two")
				  .clone()
				  .attr("id", "beep-two" + i)
				  .appendTo($(this).parent()); 
			 }
			 $(this).data("beeper", i);
		  })
		  .mouseenter(function() {
			 $("#beep-two" + $(this).data("beeper"))[0].play();
		  });
		$("#beep-two").attr("id", "beep-two0");
</script>
 
SINep is offline
 
Last edited by SINep; 03-24-2012 at 07:41 PM.
broast
Veteran
Old
9 - 03-24-2012, 07:42 PM
Reply With Quote
hrmmm

yes

i see

i think something like this should do it
Code:
<script>
		var outside=false;
		$(":not(#nav2 a)").mouseenter(function(){ outside=true });
		$("#nav2 a").mouseleave(function(){ outside=true });
		$("#nav2 a")
		  .each(function(i) {
			 if (i != 0) { 
				$("#beep-two")
				  .clone()
				  .attr("id", "beep-two" + i)
				  .appendTo($(this).parent()); 
			 }
			 $(this).data("beeper", i);
		  })
		  .mouseenter(function() {
			if(outside)
			{
  			 outside = false;
			 $("#beep-two" + $(this).data("beeper"))[0].play();
			}
		  });
		$("#beep-two").attr("id", "beep-two0");
</script>
edit: oh since you are newish, var outside is either true or false, true when the mouse is outside #nav2 a, or hovering over it at pageload because it is initially set to false, and set to true when the mouse enters anything that isnt #nav2 a (:not selector) or when it simply leaves nav2 a (mouseleave), and on the mouse enter it tests if its true ( if(outside) ), and if it is, it proceeds to beep and reset the outside switch to false
 
broast is offline
 
Last edited by broast; 03-24-2012 at 07:46 PM.
epidemic
VeteranX
Old
10 - 03-24-2012, 07:43 PM
Reply With Quote
u should make it so when i right click it says something about not stealing ur code. u know like in the 90s
 
epidemic is online now
 
SINep
VeteranX
Old
11 - 03-24-2012, 07:50 PM
Reply With Quote
Quote:
Originally Posted by broast View Post
hrmmm

yes

i see

i think something like this should do it
Code:
<script>
		var outside=false;
		$(":not(#nav2 a)").mouseenter(function(){ outside=true });
		$("#nav2 a").mouseleave(function(){ outside=true });
		$("#nav2 a")
		  .each(function(i) {
			 if (i != 0) { 
				$("#beep-two")
				  .clone()
				  .attr("id", "beep-two" + i)
				  .appendTo($(this).parent()); 
			 }
			 $(this).data("beeper", i);
		  })
		  .mouseenter(function() {
			if(outside)
			{
  			 outside = false;
			 $("#beep-two" + $(this).data("beeper"))[0].play();
			}
		  });
		$("#beep-two").attr("id", "beep-two0");
</script>
edit: oh since you are newish, var outside is either true or false, true when the mouse is outside #nav2 a, or hovering over it at pageload because it is initially set to false, and set to true when the mouse enters anything that isnt #nav2 a (:not selector) or when it simply leaves nav2 a (mouseleave), and on the mouse enter it tests if its true ( if(outside) ), and if it is, it proceeds to beep and reset the outside switch to false
Worked perfectly, thanks to ye sir!
I need to learn jQuery.
 
SINep is offline
 


Go Back   TribalWar Forums > TribalWar Community > General Discussion
Reload this Page Is there a jQuery mouse event for entering an element from outside only?

Social Website Bullshit

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

AGENT: CCBot/2.0 (http://commoncrawl.org/faq/) / Y
All times are GMT -5. The time now is 03:22 AM.