Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.

Commit 9309ac1

Browse files
author
Diego
committed
fixing virtual scrolling for WP
1 parent 68c8301 commit 9309ac1

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/scroller.css

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,6 @@
7575
text-size-adjust: none;
7676
}
7777

78-
.scroll-horizontal {
79-
-ms-touch-action: pan-x;
80-
touch-action: pan-x;
81-
}
82-
83-
.scroll-vertical {
84-
-ms-touch-action: pan-y;
85-
touch-action: pan-y;
86-
}
87-
8878
.scroll-vertical, .scroll-vertical .surface {
8979
width: 100%;
9080
}

src/surface-manager.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,18 @@
2424
RAF = w.requestAnimationFrame,
2525
Logger = SCROLLER.Logger,
2626
INITIAL_SURFACES = 10;
27-
27+
28+
2829
function SurfaceManager() {}
2930

31+
SurfaceManager.matrixTransform = function (x, y) {
32+
return 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,' + x +',' + y + ', 0, 1)';
33+
};
34+
35+
SurfaceManager.translateTransform = function (x, y) {
36+
return 'translate3d(' + x +'px,' + y + 'px, 0)';
37+
};
38+
3039
SurfaceManager.prototype = {
3140
/* Bootstrap function */
3241
init: function () {
@@ -39,11 +48,24 @@
3948
this.on('destroy', this._destroySurfaceManager);
4049
},
4150
_initializeSurfaceManager: function () {
51+
this._initTransformFunction();
4252
this._bootstrapItems();
4353
this._initializeSurfaces();
4454
this._setActiveOffset();
4555
this._initializePositions();
4656
this._setInfiniteScrollerSize();
57+
this._setWrapperState();
58+
59+
},
60+
_initTransformFunction: function () {
61+
this._transformFnc = this.opts.useNativeScroller ? SurfaceManager.translateTransform : SurfaceManager.matrixTransform;
62+
},
63+
_setWrapperState: function () {
64+
if (this.opts.useNativeScroller) {
65+
// Using native scroller, we dont need the "scroller" div anymore
66+
this.wrapper.removeChild(this.scroller);
67+
}
68+
4769
},
4870
_destroySurfaceManager: function () {
4971
var docfrag = w.document.createDocumentFragment();
@@ -161,7 +183,7 @@
161183
offsetX = config.preCalculateSize ? offset - width : offset;
162184
}
163185

164-
surface.dom.style[STYLES.transform] = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,' + offsetX +',' + offsetY + ', 0, 1)';
186+
surface.dom.style[STYLES.transform] = this._transformFnc(offsetX, offsetY);
165187

166188
surface.state = 1;
167189
surface.contentIndex = index;
@@ -185,6 +207,7 @@
185207
},
186208
_attachSurfaces: function (surfaces) {
187209
var docfrag = w.document.createDocumentFragment(),
210+
target = this.opts.useNativeScroller ? this.wrapper : this.scroller,
188211
surface, i;
189212

190213
for (i = 0 ; i < surfaces.length; i++) {
@@ -193,7 +216,7 @@
193216
this.surfacesPool.push(surface);
194217
}
195218

196-
this.scroller.appendChild(docfrag);
219+
target.appendChild(docfrag);
197220
},
198221
_getAvailableSurface: function () {
199222
var pool = this.surfacesPool,
@@ -478,7 +501,7 @@
478501

479502
if (surface) {
480503
diff = spaceBottom ? this.wrapperHeight : bottomOffset;
481-
surface.style[STYLES.transform] = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,' + diff + ', 0, 1)';
504+
surface.style[STYLES.transform] = this._transformFnc(0, diff);
482505
}
483506
},
484507
_appendPullToLoad: function () {

0 commit comments

Comments
 (0)