On my page, I have two panels where the left panel contains a list of items stacked on top of each other and when I click/select one of the items, more information about the selected item is displayed in the right panel. I needed the right panel to be scrollable so added native-like momentum scrolling to this panel as below -
#rightPanel {
position:absolute;
top:50px;
height:400px;
width:500px;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
}
To move through the list of items in the left panel, I have added single finger swipe. It works fine but when I swipe for the next item, the right panel is already scrolled which is not desired. To fix the issue added this small routine and it scrolls the rightPanel content back to top on every swipe but there is a considerable amount of delay which makes it feel like the content is loading slowly.
var scrollStopper = function() {
if ( (swipe == 'right') || (swipe == 'left') )
document.getElementById("rightPanel").scrollTop = 0;
document.getElementById('rightPanel').addEventListener('scroll', scrollStopper);
Now without momentum scrolling things work as expected. Any ideas on how to scroll right panel back to top on each swipe without causing the delay?