...

View Full Version : suppress DIV scrolling on keydown



wac
11-02-2006, 05:30 PM
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.

brandonH
11-02-2006, 06:04 PM
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;}">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum