在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Popmotion/popmotion开源软件地址(OpenSource Url):https://github.com/Popmotion/popmotion开源编程语言(OpenSource Language):JavaScript 69.4%开源软件介绍(OpenSource Introduction):The animator's toolboxPopmotion is:
Quick startnpm install popmotion import { animate } from "popmotion"
animate({
from: 0,
to: 100,
onUpdate: latest => console.log(latest)
}) Animationanimate
import { animate } from "popmotion"
animate({
from: 0,
to: 100,
onUpdate: latest => console.log(latest)
}) It can animate numbers: animate({ from: 0, to: 100 }) Or strings of the same type: animate({ from: "0px", to: "100px" })
animate({ from: "#fff", to: "#000" }) The strings can be pretty complex, for instance box shadows or SVG path definitions. The only limitation is that the numbers and colors contained within must be in the same order: animate({
from: "0px 0px 0px rgba(0, 0, 0, 0)",
to: "10px 10px 0px rgba(0, 0, 0, 0.2)"
}) The type of animation performed will be automatically detected from the provided options, or can be chosen manually by defining OptionsThese options can be set for all animations: fromAn initial value to start the animation from. Defaults to animate({
from: "linear-gradient(#e66465, #9198e5)",
to: "linear-gradient(#9198e5, #e66465)"
}) elapsedSets an initial elapsed time, in milliseconds. Set to a negative value for a delay. animate({
to: 100,
elapsed: -300
}) repeatThe number of times to repeat the animation. Set to animate({
to: 100,
repeat: 2
}) repeatDelayThe duration, in milliseconds, to wait before repeating the animation. animate({
to: 100,
repeat: 2,
repeatDelay: 200
}) repeatTypeEither
animate({
to: 100,
repeat: 2,
repeatType: "reverse"
}) driverBy default, the animation will be driven by a A const xrDriver = session => update => {
let latestRequestId = 0
let prevTimestamp = performance.now()
const step = timestamp => {
const delta = timestamp - prevTimestamp
prevTimestamp = timestamp
update(delta)
latestRequestId = session.requestAnimationFrame(step)
}
let latestRequestId = session.requestAnimationFrame(step)
return () => session.cancelRequestAnimationFrame(latestRequestId)
}
animate({
to: 100,
driver: xrDriver(xrSession)
}) type
animate({
to: 100,
type: "spring"
}) Lifecycle eventsThe following lifecycle events are available for all animations: onUpdateThis is called every frame the animation fires with the latest computed value. animate({
to: 100,
onUpdate: latest => console.log(latest)
}) onPlayThis is called when the animation starts. Currently this automatically when animate({
to: 100,
onPlay: () => {}
}) onCompleteThis is called when the animation successfully completes. animate({
to: 100,
onComplete:() => {}
}) onRepeatThis is called when an animation repeats. animate({
to: 100,
repeat: 2,
onRepeat: () => {}
}) onStopThis is called when the animation is stopped by the const animation = animate({
to: 100,
onStop: () => {}
})
animation.stop() Keyframes optionsA keyframes animation is the default animation type and it can be defined either with a animate({ from: 0, to: 100 }) Or as a series of keyframes provided to the animate({ to: [0, 100, 200] }) toA single value to animate to, or an array of values to animate through. animate({
to: ["#0ff", "#f00", "#0f0"]
}) If durationThis defines the duration of the animation, in milliseconds. animate({
to: 100,
duration: 300
}) easeThis is an easing function, or array of functions, to use when easing between each keyframe. import { animate, linear, easeInOut } from "popmotion"
animate({
to: 100,
ease: linear
})
animate({
to: ["#fff", "#000", "#f00"],
ease: [linear, easeInOut]
}) If set as any array, the length of this array must be one shorter than the number of values being animated between. offsetThis is an array of values between This array should be the same length as the number of defined keyframes. animate({
to: ["#fff", "#000", "#f00"],
offset: [0, 0.2, 1]
}) Spring optionsSprings are great for creating natural-feeling interfaces and dynamic interruptable animations. A spring animation will be used if any of the Note: A spring simulation is inherently numerical so if it's given a color, array or object, it runs the animation from toA single value to animate to. animate({
to: 100,
type: "spring"
}) If stiffnessThis defines the stiffness of the spring. A higher stiffness will result in a snappier animation. Defaults to animate({
to: 100,
stiffness: 1000
}) dampingThis is the opposing force to Defaults to animate({
to: 100,
damping: 50
}) massThis is the mass of the animating object. Heavier objects will take longer to speed up and slow down. Defaults to animate({
to: 100,
mass: 2
}) velocityThe initial velocity, in units per second, of the animation. animate({
to: 100,
velocity: 1000
}) durationThe duration of the spring, in milliseconds. Will be overridden by animate({
to: 100,
duration: 1000
}) bounceThe bounciness of the spring, as a value between Will be overridden by animate({
to: 100,
bounce: 0.2
}) restDeltaThe distance from the animation target at which the animation can be considered complete. When both animate({
to: 100,
restDelta: 0.5
}) restSpeedThe absolute velocity, in units per second, below which the animation can be considered complete. When both animate({
to: 100,
restSpeed: 5
}) Playback controls
Currently this only includes a stopStops the animation. const playback = animate({ from: 0, to: 100 })
playback.stop() inertiaThe OptionsIn addition to velocityThe initial velocity, in units per second, of the animation. inertia({
from: 0,
velocity: 100
}) powerA constant with which to calculate a target value. Higher power = further target. Defaults to inertia({
from: 0,
power: 0.3
}) timeConstantAdjusting the time constant will change the duration of the deceleration, thereby affecting its feel. Defaults to inertia({
from: 0,
velocity: 100,
timeConstant: 400
}) modifyTargetA function that receives the calculated target and returns a new one. Useful for snapping the target to a grid. const roundToNearest = target => v => Math.ceil(v / target) * target
inertia({
from: 0,
velocity: 100,
modifyTarget: roundToNearest(100)
}) minThe minimum value at which the animation will switch from gradual deceleration and use a spring animation to snap to this point. inertia({
from: 50,
velocity: -100,
min: 0
}) |