Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    wac
    wac is offline
    Regular Coder wac's Avatar
    Join Date
    Sep 2002
    Location
    Cary, North Carolina, USA
    Posts
    359
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question suppress DIV scrolling on keydown

    I've written my own list object using a DIV with overflow:auto and a table containing the list items. On up/down arrow I move the highlight focus through the list items. Since the scrollbar automagically captures up/down arrow and does its own thing, I've done event.returnValue = false so the scroll bar doesn't get the event and my stuff works well. This is fine in IE, but in firefox I can't get the same to occur. I've tried all the incantations I know for cross browser event cancellation using the function below to no avail. I cannot get firefox to behave the same as IE. Firefox DIV scroll bars
    still capture up/down arrow and scroll the DIV.

    function stopEventPropagation(e)
    {
    if (undefined == e) e = window.event;

    e.cancelBubble = true;
    e.returnValue = false ;
    if (undefined != e.stopPropagation) e.stopPropagation();
    }
    What my code does is to scroll the DIV only if the highlight focus is moved outside the visible part of the DIV, the way a real list works.
    Wayne Christian

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    try setting an event handler on the body itself
    and inside that detects if the div has focus or not, if it does then return false.
    i would also recommend using onkeydown, as the window's scroll may be triggered by onkeydown, and if you use onkey up, it would not cancel out the onkeydown event of the window.

    <body onkeydown="javascript:if(yourdiv.focus()){return false;}else{return true;}">
    Last edited by brandonH; 11-02-2006 at 08:29 PM. Reason: typo
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.


  •  

    Posting Permissions

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