I need to reimplement the scroll functionality over an overflow area, so that the mousewheel changes the current selection rather than the scroll position.
To do this at the very least, I need to block the default scroll action of the browser. From what I can tell knockout does this by default, provided that you don't return 'true' from the event handler.
However it doesn't seem to work, nor does calling 'preventDefault' on the event explicitly. This problem must be specific to the scroll event.
scrolled: function (vm, event) {
event.preventDefault();
return false;
}
Example: http://jsfiddle.net/vjLqauq5/2/
Hat tip to Andrey for pointing out that you should use the mousewheel event rather than the scroll event.
From the mousewheel event,
deltaY
will give you the scroll direction, which you can use to change which item is selected:http://jsfiddle.net/vjLqauq5/8/