virtual-scroll
Advanced tools
Comparing version 1.2.1 to 1.3.1
{ | ||
"name": "virtual-scroll", | ||
"version": "1.2.1", | ||
"version": "1.3.1", | ||
"description": "Smooth fake scroll using CSS transform", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -45,4 +45,5 @@ virtual-scroll | ||
- limitInertia: if true, will leverage [Lethargy](https://github.com/d4nyll/lethargy) to avoid everlasting scroll events (mostly on Apple Mouse, Trackpad, and free-wheel mouse). *Defaults to false.* | ||
- passive: if used, will use [passive events declaration](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners) for the wheel and touch listeners. Can be true or false. *Defaults to undefined.* | ||
### License | ||
MIT. |
@@ -51,2 +51,6 @@ 'use strict'; | ||
this.bodyTouchAction = null; | ||
if (this.options.passive !== undefined) { | ||
this.listenerOptions = {passive: this.options.passive}; | ||
} | ||
} | ||
@@ -157,8 +161,8 @@ | ||
VirtualScroll.prototype._bind = function() { | ||
if(support.hasWheelEvent) this.el.addEventListener('wheel', this._onWheel); | ||
if(support.hasMouseWheelEvent) this.el.addEventListener('mousewheel', this._onMouseWheel); | ||
if(support.hasWheelEvent) this.el.addEventListener('wheel', this._onWheel, this.listenerOptions); | ||
if(support.hasMouseWheelEvent) this.el.addEventListener('mousewheel', this._onMouseWheel, this.listenerOptions); | ||
if(support.hasTouch) { | ||
this.el.addEventListener('touchstart', this._onTouchStart); | ||
this.el.addEventListener('touchmove', this._onTouchMove); | ||
this.el.addEventListener('touchstart', this._onTouchStart, this.listenerOptions); | ||
this.el.addEventListener('touchmove', this._onTouchMove, this.listenerOptions); | ||
} | ||
@@ -165,0 +169,0 @@ |
@@ -79,2 +79,20 @@ 'use strict'; | ||
test('Passive listener test', function(assert) { | ||
var vNone = new VirtualScroll(); | ||
var vPassive = new VirtualScroll({ | ||
passive: true | ||
}); | ||
var vActive = new VirtualScroll({ | ||
passive: false | ||
}); | ||
assert.ok(vNone.listenerOptions === undefined, 'No passive option'); | ||
assert.ok(vPassive.listenerOptions.passive, 'Passive event listener'); | ||
assert.notOk(vActive.listenerOptions.passive, 'Active event listener'); | ||
vPassive.destroy(); | ||
vActive.destroy(); | ||
vNone.destroy(); | ||
assert.end(); | ||
}); | ||
test('Off test', function(assert) { | ||
@@ -94,2 +112,3 @@ var v = new VirtualScroll(); | ||
assert.ok(scrollCount === 1, 'Scroll handler should have fired only once.'); | ||
v.destroy(); | ||
assert.end(); | ||
@@ -96,0 +115,0 @@ }); |
15743
319
49