www.webdeveloper.com
Results 1 to 5 of 5

Thread: onmouseover/onmouseout problem

  1. #1
    Join Date
    Jun 2005
    Posts
    26

    onmouseover/onmouseout problem

    Hi

    I want to make a dhtml menu.
    I have the following issue: I want to attach a function to all "li" elements witch have "ul" childs on mouse over event.

    Here is my code:


    var ulEls = document.getElementById("navmeister").getElementsByTagName("ul");
    for (var i=0; i<ulEls.length; i++) {

    stPos[i] = ulEls[i].offsetHeight;
    topPos[i] = 20-stPos[i];

    elem = ulEls[i]

    ulEls[i].parentNode.onmouseover=function() {
    scrollit("down",elem, 0 );
    }
    ulEls[i].parentNode.onmouseout=function() {
    scrollit("up",elem, 0);
    }

    }

    The code is not working how I expect. All attached functions have the same parameters. elem parameter is allawys the last "ul" element found so if i hover any menu item is shown the last submenu.

    Why is bot parsed corect parameter ?
    Can anyone help me with that ?

    PS: I tried attachEvent() but no good result.

    Thanks,
    Alin.

  2. #2
    Join Date
    Dec 2005
    Location
    Washington, DC
    Posts
    228
    thats because elem does not change for each function...for every function created, it refers to the global variable elem.

    this might work for what you want to accomplish
    Code:
    var liEls = document.getElementById("navmeister").getElementsByTagName("li");
    for (var i=0; i<liEls.length; i++) {
    var hasULs = liEls[i].getElementsByTagName('ul').length > 0;
    if(hasULs){
    liEls[i].onmouseover=function() {
    scrollit("down",this, 0 );
    }
    liEls[i].onmouseout=function() {
    scrollit("up",this, 0);
    }
    }
    }
    Last edited by Selrach; 02-22-2006 at 11:52 AM. Reason: removed extraneous code line
    "God didn't create the world in seven days, he pulled an all-nighter on the sixth."

  3. #3
    Join Date
    Jun 2005
    Posts
    26
    Thanks Selrach!

    That fixed one af my issues.
    The second parameter should be the ul element, but this is not a problem.

    Is any posibility to pass the third parameter (witch now is "0") the value of the counter "i"?

    Thanks again.

  4. #4
    Join Date
    Dec 2005
    Location
    Washington, DC
    Posts
    228
    hmm..this might work
    Code:
    var liEls = document.getElementById("navmeister").getElementsByTagName("li");
    for (var i=0; i<liEls.length; i++) {
    var hasULs = liEls[i].getElementsByTagName('ul').length > 0;
    if(hasULs){
    liEls[i].i = i;
    liEls[i].onmouseover=function() {
    scrollit("down",this, this.i );
    }
    liEls[i].onmouseout=function() {
    scrollit("up",this, this.i );
    }
    }
    }
    "God didn't create the world in seven days, he pulled an all-nighter on the sixth."

  5. #5
    Join Date
    Jun 2005
    Posts
    26
    Thanks a lot!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles