Calculate scroll position more correctly