-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathjquery.scrollSync.js
More file actions
29 lines (29 loc) · 797 Bytes
/
Copy pathjquery.scrollSync.js
File metadata and controls
29 lines (29 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
* jquery.scrollSync
* Synchronize scroll between multiple containers with varying size
* Date: 20151201
*
* Thomas Frost
* http://xtf.dk/
*
* Required:
* jQuery
* http://jquery.com/
*
* Usage:
* $('.scrollable').scrollSync();
*/
(function ($) {
$.fn.scrollSync = function () {
var $this = $(this);
$this.on('scroll', function (e) {
var $sender = $(e.currentTarget);
if ($sender.is(":hover")) {
var percentage = this.scrollTop / (this.scrollHeight - this.offsetHeight);
$this.not($sender).each(function (i, other) {
other.scrollTop = percentage * (other.scrollHeight - other.offsetHeight);
});
}
});
};
})(jQuery);