move scroll/pan logic to javascript