我想在famo.us中構建粘滯滾動視圖,並且我陷入兩處。在famo.us中構建粘滯滾動視圖
1)身體在標題頂部滾動。當我添加一個Transform.translate(0,0,1)到標題中之前,它將它添加到_mainScrollview它什麼都不做。
2)_mainScrollview卡住時,我如何保持_bodyScrollview的速度?
/***
* A view that scrolls, sticks the header at stickAt,
* and then allows the body to scroll.
*/
function Sticky(options) {
View.apply(this, arguments);
options = options || {};
this.options = Object.create(Sticky.DEFAULT_OPTIONS);
for (var i in Sticky.DEFAULT_OPTIONS) {
if (options[i] !== undefined) this.options[i] = options[i];
}
// setup the scrollviews
this._bodyScrollview = new Scrollview({});
this._bodyScrollview.sequenceFrom([this.options.body]);
this._mainScrollview = new Scrollview({});
this._mainScrollview.sequenceFrom([this.options.header, this._bodyScrollview]);
this._eventInput.pipe(this._mainScrollview);
// track the velocities
this._mainScrollview.sync.on('update', function (data) {
this._mainVelocity = data.velocity;
}.bind(this));
this._bodyScrollview.sync.on('update', function (data) {
this._bodyVelocity = data.velocity;
}.bind(this));
this.add(this._mainScrollview);
}
Sticky.prototype.render = function() {
// If the main scrollview is scrolled up (velocity < 0)
// past the stickAt point, stick it and unstick the body scrollview.
if (this._mainVelocity < 0) {
if (this._mainScrollview.getPosition() >= this.options.stickAt) {
this._eventInput.unpipe(this._mainScrollview);
this._eventInput.pipe(this._bodyScrollview);
Tools.forcePosition(this._mainScrollview, this.options.stickAt, true);
this._mainVelocity = 0;
}
}
// If the main scrollview is scrolled down (velocity > 0)
// past 0, stick it and unstick the main scrollview.
if (this._bodyVelocity > 0) {
console.log(this._bodyScrollview.getPosition());
if (this._bodyScrollview.getPosition() <= 0) {
this._eventInput.unpipe(this._bodyScrollview);
this._eventInput.pipe(this._mainScrollview);
Tools.forcePosition(this._bodyScrollview, 0, true);
this._bodyVelocity = 0;
}
}
return View.prototype.render.call(this);
};
/**
* Force a scrollview to a position
*/
Tools.forcePosition = function (scrollview, position, noSpring) {
if (noSpring) {
scrollview._springState = 0;
scrollview._physicsEngine.detachAll();
}
scrollview.setVelocity(0);
scrollview.setPosition(position);
};
來源位於http://github.com/famous/famous,文檔位於https://famo.u s/docs – jonperl