0.0.1 • Published 7 years ago

hilo-parallax v0.0.1

Weekly downloads
1
License
-
Repository
github
Last release
7 years ago

hilo-parallax


Hilo Parallax Component

NPM version build status Test coverage gemnasium deps node version npm download


Install

npm i hilo-parallax

hilo-parallax

Usage

import Stage from 'hilojs/view/Stage';
import Ticker from 'hilojs/util/Ticker';
import Ease from 'hilojs/tween/Ease';
import Parallax from 'hilo-parallax';

// hilo stage
var stage = new Stage({
  renderType: 'canvas',
  canvas,
  width: 375,
  height: 614,
});
canvas.width = 375;
canvas.height = 614;
this.ticker = new Ticker(30);
this.ticker.addTick(stage);
this.ticker.start();

const bgWrapper = new Parallax({
  childrens: [
    {
      depth: 0.5,
      children: 'https://zos.alipayobjects.com/rmsportal/vQbYqyotOjnnTPfpjpzN.png',
      imageData: {
        cpPosition: -800,
        y: 200,
      },
    },
    {
      depth: 1,
      children: 'https://zos.alipayobjects.com/rmsportal/gVBfGmjSskHNvmScZMGm.png',
      imageData: {
        cpPosition: -800,
        y: 250,
      },
    },
  ],
  type: 'x',
  duration: 10000,
  ease: Ease.Linear.EaseNone,
  width: this.width,
  height: this.height,
  loop: true,
  startPercent: 0.2,
});
stage.addChild(bgWrapper);
bgWrapper.cameraAnimateTo(-800);

API

Parallax extends Container

nametypedefaultdescription
childrensArraynullparallax 的子级
typestringxparallax 动画类型: x, y, xy; 如果为 xy, cameraAnimateTo 里的 value 可以为 { x, y };
durationnumber1000初始时间设定
easehilo.EaseEase.Quad.EaseOut动画缓动
loopbooleanfalse是否循环播放,注: 如果为 true, cameraAnimateTo 只能触发一次
invertbooleanfalseloop 时, 第二遍是否反向播放
cameraStartnumber0镜头位置
startPercentnumber00 - 1 之间的百分比值; 开始显示镜头所在动画轴上的百分比
stackstringresettype: add, reset; 两种方式; add: 为不结束前面一个动画,往动画队列里添加后面即将发生的动画, 为多轨动画, 比较耗性能; reset: 保持单个动画的运行,强制结束前面一个动画, 单轨动画。

childrens

nametypedefaultdescription
children<Hilo.View> or stringnull子级元素, 如果是 string, 将自动创建 Bitmap;
depthnumbernull当前子级深度, 控制视差的
imageDataobjectnull只适用 children 为 string 时 { ...(所有 Bitmap 属性), cpPosition }: cpPosition 开启拷贝图片,并设置所在位置。

cameraAnimateTo(value, animateProps);

动画调用方法:

value: 动画参数;

animateProps: { duration, ease }; 替换初始设置的动画值;

Development

npm install
npm start

Example

http://localhost:8301/examples/

License

hilo-parallax is released under the MIT license.