how to add parallax to a Scrollview?

妖精的绣舞 提交于 2019-12-05 22:27:23

To answer your question, the way to pipe scroll events is to use the sync property of scrollview to get updates on scroll.

That is..

scrollview.sync.on('start',function(e){ // Do Something });
scrollview.sync.on('update',function(e){ // Do Something });
scrollview.sync.on('end',function(e){ // Do Something });

However for rendering objects in sync and ensuring precision on such, I have found the Engine prerender function to be wonderful.

So I would do something like this.

Engine.on('prerender',function(){

  // Divide by scalar to get effect

  var parallaxEffect = 2.0
  var bgPos = -contentScrollview.getPosition() / parallaxEffect;

  imageView.state.setTransform(Transform.translate(0,bgPos,0)));

})

Hope these pointers help!

This is a bit of a lazy answer, but let me link you to one of the famous demos created by their HackerLab alumni. It demonstrates using famous to create some complex scrolling/swiping animations.

I've learned a lot about Famo.us from the code in the demos, however this hasn't been made available to those outside the beta list yet. So I cloned the project files.

UltraVisual: A Parallax Scrolling Demo

https://github.com/KraigWalker/famous-UltraVisual

A more advanced scrolling animation demo

https://github.com/KraigWalker/famous-IFTTT

Hope this helps you out!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!