I knew where the bug was coming from as soon as i saw your code, however it might take me some time to figure out a way to explain the logic causing the bug to myself or to you.
For now, here is the solution to increasing the step of the scroll based on the JSFiddle example you provided: (However make sure you are not running an ancient version of JQuery, otherwise this solution won't work, tested on version 1.9.1 and everything works)
$(function(){
$(".wmd-view-topscroll").on("scroll",function(){
clearTimeout($.data(this, 'scrollTimer'));
$.data(this, 'scrollTimer', setTimeout(function() {
$(".wmd-view").scrollLeft($(".wmd-view-topscroll").scrollLeft());
}, 50));
});
$(".wmd-view").on("scroll", function(){
$(".wmd-view-topscroll").scrollLeft($(".wmd-view").scrollLeft());
});
});
What the part i added does, is it waits for the scrolls to finish before it sets the new scroll on the other element, i just felt like setting the timeout to 50
, set it to anything you like as long as it is long enough for the scrollbar to reach the point where you clicked.
Edit 1: thanks to @Schlumpf for clearing up my doubts, you have 2 events and the other is called whenever you call one of them, and that other one in turn calls back the one that called it and sets its new scroll to be the current scroll of itself (the second element's scroll) therefore overwriting the original scroll you wanted.
As @Schlumpf pointed out, just try to make a console.log([whatever])
whenever you call one of the scroll events to see what we are talking about.
Please ask in the comments if you need me to elaborate more.
Edit 2: As Rob explained in the comments, this is not an easy question to answer because the problem is not clear enough. So try to be explain your problem in more detail next time OP. And just in case the fiddle we are talking about is deleted by its original owner or whatever, here is a link to the fiddle we are talking about, just in case.