-
Notifications
You must be signed in to change notification settings - Fork 0
Install and Simple use
npm i --save @haztivity/hz-anim
hz-anim uses velocity.js under the hood.
- JQuery
- velocity.js
- haztivity/core
- Import @haztivity/hz-anim
- Add HzAnim to the page
- Assign an event to listen with
data-hz-anim-on
- Set the properties o transition to anim with
data-opt-hz-anim-do
import {PageFactory, Page, PageController, PageRegister} from "@haztivity/core";
import template from "./page.pug";
import {HzAnimResource} from "@haztivity/hz-anim";
export let page: PageRegister = PageFactory.createPage(
{
name: "myPage",
resources: [
HzAnimResource
],
template: template
}
);
button(
data-hz-resource="HzAnim"
data-opt-hz-anim-on="click"
data-opt-hz-anim-do={"rotateZ":"45deg"}
) Do to me
or
<button
data-hz-resource="HzAnim"
data-opt-hz-anim-on="click"
data-opt-hz-anim-do='{"rotateZ":"45deg"}'
>
Do to me
</button>
This will perform a rotate in the Z axis from 45 degrees.
By default, the animation is performed to the item itself, to see how to apply the animation to other element plase go to Apply animation to other targets
HzAnim uses velocity.js, a very efficient js library to perform animations.
It's possible to animate any of the properties and transitions available in velocity.js and use all the options.
To apply the transforms to other elements, use the data-opt-hz-anim-to
, accepts any jquery valid selector.
See jquery selectors for more info.
button(
data-hz-resource="HzAnim"
data-opt-hz-anim-on="click"
data-opt-hz-anim-do={"rotateZ":"45deg"}
data-opt-hz-anim-to=".target"
) Do to .target
button.target Target
or
<button
data-hz-resource="HzAnim"
data-opt-hz-anim-on="cli###ck"
data-opt-hz-anim-do='{"rotateZ":"45deg"}'
data-opt-hz-anim-to=".target"
>
Do to .target
</button>
<button class="target">Target</button>
By default, the animation is repeatable and could be performed multiple times.
For one time execution, set the repeatable
option to false
button(
data-hz-resource="HzAnim"
data-opt-hz-anim-repeatable="false"
data-opt-hz-anim-on="click"
data-opt-hz-anim-do={"rotateZ": "+=45deg"}
) Do to me only once
or
<button
data-hz-resource="HzAnim"
data-opt-hz-anim-repeatable="false"
data-opt-hz-anim-on="click"
data-opt-hz-anim-do='{"rotateZ":"+=45deg"}'
>
Do to me only once
</button>