Skip to content

Commit

Permalink
Fixes slow scrolling when scroll sync is enabled
Browse files Browse the repository at this point in the history
Some browsers have an animated scroll effect, where it smears
a single scroll event over mutiple smaller scroll events.

Whenever this effect lasted for more than 10 milliseconds
each div's (split editor/preview) scroll even would cancel
the other, which caused scrolling to be really slow.
  • Loading branch information
benjamin-albert committed May 10, 2016
1 parent 2effc64 commit 59d8ab8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions public/js/user/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ module.exports =
vm.profile = userService.profile;

var $divs = jQuery('.split-editor, .split-preview');
var $allowed = $divs;
var sync = function(e) {
var
$other = $divs.not(this).off('scroll'),
other = $other[0],
percentage = this.scrollTop / (this.scrollHeight - this.offsetHeight);
var $this = jQuery(this);

other.scrollTop = Math.round(percentage * (other.scrollHeight - other.offsetHeight));
if ($this.is($allowed)) {
var
other = $divs.not(this)[0],
percentage = this.scrollTop / (this.scrollHeight - this.offsetHeight);

$timeout(function() {
$other.on('scroll', sync);
}, 10);
other.scrollTop = Math.round(percentage * (other.scrollHeight - other.offsetHeight));

$allowed = $this;
} else {
$allowed = $divs;
}

return false;
};
Expand Down

0 comments on commit 59d8ab8

Please sign in to comment.