Connect with:
About Me
Alessandro Annini
I'm a freelance developer currently working at I really love framework and its amazing potential and if you're like me, and you want the web to win, please share some snippet of code for the community and grow faster with us
Meta Code | Scrollable list view with modifiers

Scrollable list view with modifiers

14 Jul Scrollable list view with modifiers

It was once asked on IRC how to apply a modifier to an item in the Scrollview, based on it’s actual location in the visible region. Here, I will show you one way to achieve it.

First, you add a physics engine and attach a particle body to it:

this._engine = new PhysicsEngine();
this._tracker = new Particle();

Then you move it based on the distance coming from the GenericSync. In our case TouchSync fires ‘update’ event every time we drag our scroller. We listen for this event and update the position of the particle:

this._eventInput.on('update', _handleUpdate);

function _handleUpdate(event) {
    var delta =;
    this.setPosition(this.getPosition() - delta);

Scrollik.prototype.getPosition = function getPosition() {
    return this._tracker.getPosition()[0];

Scrollik.prototype.setPosition = function setPosition(x) {
    this._tracker.setPosition([x, 0, 0]); // [x, y, z]

And we update our scroller’s position, based on the location of the particle, so that the positions of both are same:


Now, we have a good reference of where exactly our scroller is. Time to use it to affect the items in the list! To do that, we would first attach a Modifier for every item in the list and save them to an array for later use:

for (var i = 0; i < surfaces.length; i++) {
    var scaleMod = new Modifier({ 
        align: [1, .5],
        origin: [1, .5]

By knowing the distance the scroller has moved to the side, the width of each surface and the width of the window, we can easily know which surface is entering the view or leaving it. Having that info at our hands, we can affect the modifiers of these elements.

Here is an example of the solution: