scroll-syncer
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -15,5 +15,5 @@ // detect if user-agent support passive event binding | ||
function ScrollSyncer (vertical, horizontal) { | ||
this._vertical = vertical | ||
this._horizontal = horizontal | ||
this._from = null | ||
this._vertical = vertical | ||
this._horizontal = horizontal | ||
this._from = null | ||
this._to = [] | ||
@@ -25,21 +25,21 @@ | ||
ScrollSyncer.prototype.from = function (target) { | ||
if (!target || !target.addEventListener) return | ||
this._from = target | ||
this._from.addEventListener('scroll', this._scrollHandler, bindOptions) | ||
this.sync() | ||
if (!target || !target.addEventListener) return | ||
this._from = target | ||
this._from.addEventListener('scroll', this._scrollHandler, bindOptions) | ||
this.sync() | ||
} | ||
ScrollSyncer.prototype.to = function (target) { | ||
if (!target) return | ||
this._to.push(target) | ||
this.sync() | ||
if (!target) return | ||
this._to.push(target) | ||
this.sync() | ||
} | ||
ScrollSyncer.prototype.sync = function () { | ||
if (this._from) { | ||
this._to.forEach(function (el) { | ||
if (this._vertical) el.scrollTop = this._from.scrollTop | ||
if (this._horizontal) el.scrollLeft = this._from.scrollLeft | ||
}, this) | ||
} | ||
if (this._from) { | ||
this._to.forEach(function (el) { | ||
if (this._vertical) el.scrollTop = this._from.scrollTop | ||
if (this._horizontal) el.scrollLeft = this._from.scrollLeft | ||
}, this) | ||
} | ||
} | ||
@@ -46,0 +46,0 @@ |
{ | ||
"name": "scroll-syncer", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Synchronize scoll position among several elements", | ||
@@ -5,0 +5,0 @@ "main": "index.common.js", |
5328