animejs走马灯_animejs 动画库

本文介绍如何利用animejs动画库实现走马灯效果。通过设置不同的动画参数,如translateX、opacity,结合autoplay、duration、delay和loop等属性,可以创建出平滑的循环播放动画。同时,animejs提供了丰富的回调函数,如begin、update、complete等,方便在动画的不同阶段进行交互和控制。
摘要由CSDN通过智能技术生成
Document

.target {

width: 20px;

height: 20px;

background-color: red;

}

new Vue({

el: '#app',

data() {

return {};

},

mounted() {

// 为每种属性提供特定的动画参数 https://animejs.com/documentation/#specificPropParameters

// 为动画的每个目标和属性获取不同的值 https://animejs.com/documentation/#functionBasedParameters

// 添加,减去或乘以原始值。 https://animejs.com/documentation/#relativeValues

// 帧动画 https://animejs.com/documentation/#animationKeyframes

// 播放/暂停 https://animejs.com/documentation/#playPause

// 回调函数,监听动画周期 https://animejs.com/documentation/#update

var playPauseAnim = anime({

targets: '.target',

autoplay: true, // 定义动画是否应自动启动。

// translateX: 250,

// translateX: [-20, 20], // 强制动画以指定值开始。 [from, to]

translateX: [

{ value: -20, duration: 0 },

{ value: 0, duration: 1000 },

{ value: 20, duration: 1000, delay: 2000 },

],

opacity: [

{ value: 0, duration: 0 },

{ value: 1, duration: 1000 },

{ value: 0, duration: 1000, delay: 2000 },

],

duration: 3000, // 动画的持续时间(以毫秒为单位)

delay: 1000, // 动画的延迟(以毫秒为单位)

// endDelay: 1000, // 动画结束时以毫秒为单位添加一些额外时间

easing: 'linear', // 和css一样的动画曲线 https://animejs.com/documentation/#linearEasing

// direction: 'alternate', // 定义动画的方向。 https://animejs.com/documentation/#direction

loop: true, // 定义动画的迭代次数。

// innerHTML: [0, 10000],

// round: 10, // 将值向上舍入为x小数。

//每帧都会触发回调,包括延迟时

update: function() {

// console.log('update');

},

begin: function(anim) {

console.log('begin');

},

// 每次循环开始时都会触发一次loopBegin

loopBegin() {

console.log('loopBegin');

},

// 每次动画开始更改时都会触发changeBegin

changeBegin: function(anim) {

console.log('changeBegin');

},

//每次循环完成时都会触发一次loopComplete

loopComplete: function(anim) {

console.log('loopComplete');

},

// 每次动画停止更改时都会触发changeComplete

changeComplete: function(anim) {

console.log('changeComplete');

},

// 在延迟之后触发

change: function() {

console.log('change');

},

complete: function(anim) {

console.log('结束');

},

});

},

methods: {},

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值