Skip to content

Commit

Permalink
Merge pull request joemccann#536 from benjamin-albert/master
Browse files Browse the repository at this point in the history
Fixes slow scrolling when scroll sync is enabled
  • Loading branch information
joemccann committed May 10, 2016
2 parents 2effc64 + 0d66432 commit 163893e
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions public/js/user/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,26 @@ module.exports =

vm.profile = userService.profile;

// TODO: Move this to out of here (perhaps to its own directive).
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));
// Prevents slow scrolling by only allows subsequent callbacks
// on the element that the first scroll event was triggered on.
// See #516 for details.
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 163893e

Please sign in to comment.