Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1071 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     Javascript :

Event fires prematurely.

Thread title: Event fires prematurely.
Closed Thread    
    Thread tools Search this thread Display Modes  
02-04-2008, 01:19 PM
#1
Szandor is offline Szandor
Status: Junior Member
Join date: Jan 2008
Location: Växjö, Sweden
Expertise:
Software:
 
Posts: 45
iTrader: 0 / 0%
 

Szandor is on a distinguished road

  Old  Event fires prematurely.

I have a small problem with JavaScript, and I'm a bit of a beginner so I need some help with it.

I use Mootools to hide and show a navigation bar on a website I'm currenly building. Everything works fine with the Mootools part, but my events act up a bit.

A DIV called "menu" has an "onmouseover" event on it, causing an OL to slide down. It also has an "onmouseout" to make the OL disappear again. The problem is that the events fire off like crazy when I hover my OL and its anchors, causing the menu to move, flicker and sometimes even disappear.

Putting a DIV on top of it all makes the sliding work perfectly, but the anchors completely inaccessible. I've tried a lot of other solutions as well, but nothing seems to get rid of the problem without causing new ones.

Is there a JavaScript guru around that can help me?

02-24-2008, 11:45 AM
#2
jingceawlin is offline jingceawlin
Status: I'm new around here
Join date: Feb 2008
Location:
Expertise:
Software:
 
Posts: 8
iTrader: 0 / 0%
 

jingceawlin is on a distinguished road

Send a message via Yahoo to jingceawlin

  Old

I guess that's because of event bubbling. For example, when you move your mouse into and out of any anchor inside the div, the div's mouseover and mouseout event handlers would also execute, even thought you only want them to execute when you actually move into or out of the div. Does it make sense?

03-01-2008, 08:35 AM
#3
Szandor is offline Szandor
Status: Junior Member
Join date: Jan 2008
Location: Växjö, Sweden
Expertise:
Software:
 
Posts: 45
iTrader: 0 / 0%
 

Szandor is on a distinguished road

  Old

Yes, that's it exactly. Is there a solution?

03-01-2008, 11:10 AM
#4
jingceawlin is offline jingceawlin
Status: I'm new around here
Join date: Feb 2008
Location:
Expertise:
Software:
 
Posts: 8
iTrader: 0 / 0%
 

jingceawlin is on a distinguished road

Send a message via Yahoo to jingceawlin

  Old

I don't use Mootools. But basically, event object should have a property called target(or srcElement), from which you can decide the source element which caused the event. If the event is bubbled, you just do nothing.

03-01-2008, 02:46 PM
#5
Wildhoney is offline Wildhoney
Wildhoney's Avatar
Status: Request a custom title
Join date: Feb 2006
Location: Nottingham
Expertise:
Software:
 
Posts: 1,648
iTrader: 18 / 95%
 

Wildhoney is on a distinguished road

Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney

  Old

You'll want to set a variable that prevents the latter trigger from being triggered until the former trigger has completed. In Prototype you could do something like the following:

Code:
var bTrigger = true;

if(bTrigger == true)
{
	bTrigger = false;

	pEvent = 
	{
		afterFinish: function()
		{
			bTrigger = true;
		}
	}

	new Effect.Shake($('myElement'), pEvent);
}

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed