链接: http://ianlunn.github.io/Hover/
install: npm install hover.css --save
文档: https://www.npmjs.com/package/hover.css#downloadinstall
链接: https://animate.style/
install: yarn add animate.css
链接: https://www.minimamente.com/project/magic/
install: yarn add magic.css
文档: https://www.npmjs.com/package/magic.css
动画效果: https://www.jq22.com/yanshi2754
文档: https://animate.style/
install: npm install --save jquery.transit
链接: https://animejs.com/
install: npm install animejs --save
补充文档: https://www.npmjs.com/package/animejs
安装:
npm install animejs --save yarn add animejs
引入:
import animejs from "animejs/lib/anime.es.js"
const anime = require('animejs');
语法
anime({targets:"#target1 .target2",druation:1000,easing:'easeInOutQuad',direction:'alternate'
})
targts 动画目标
targets类型:
CSS选择器、Dom/NodeList、Object、Array[types[]:CSS选择器 || Dom/NodeList || Object]
//选两个特殊的目标类型做个例子
//Object
const lv={value:0,count:0
}
anime({targets:lv,value:100,count:10,round:1,//应该是动画动的时候进行四舍五入update:()=>{//do something}
})
//Array
const nv=['.el', domNode, jsObject]
anime({targets: nv,translateX: 250
});
DIRECTION 表示交替方式
参数
normal:
动画向前播放。当它到达结尾时,它会从第一个关键帧重新开始。reverse:
从最后一个关键帧开始,在第一个关键帧结束alternate:
动画先向前播放,然后向后播放:easing 表示动画缓冲
可取值:
linear: linear
penner函数
IN | OUT | IN-OUT | OUT-IN |
---|---|---|---|
'easeInQuad' | 'easeOutQuad' | 'easeInOutQuad' | 'easeOutInQuad' |
'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic' | 'easeOutInCubic' |
'easeInQuart' | 'easeOutQuart' | 'easeInOutQuart' | 'easeOutInQuart' |
'easeInQuint' | 'easeOutQuint' | 'easeInOutQuint' | 'easeOutInQuint' |
'easeInSine' | 'easeOutSine' | 'easeInOutSine' | 'easeOutInSine' |
'easeInExpo' | 'easeOutExpo' | 'easeInOutExpo' | 'easeOutInExpo' |
'easeInCirc' | 'easeOutCirc' | 'easeInOutCirc' | 'easeOutInCirc' |
'easeInBack' | 'easeOutBack' | 'easeInOutBack' | 'easeOutInBack' |
'easeInBounce' | 'easeOutBounce' | 'easeInOutBounce' | 'easeOutInBounce' |
var demoContentEl = document.querySelector('.penner-equations-demo');
var fragment = document.createDocumentFragment();
var easingNames = ['easeInQuad','easeInCubic','easeInQuart','easeInQuint','easeInSine','easeInExpo','easeInCirc','easeInBack','easeOutQuad','easeOutCubic','easeOutQuart','easeOutQuint','easeOutSine','easeOutExpo','easeOutCirc','easeOutBack','easeInBounce','easeInOutQuad','easeInOutCubic','easeInOutQuart','easeInOutQuint','easeInOutSine','easeInOutExpo','easeInOutCirc','easeInOutBack','easeInOutBounce','easeOutBounce','easeOutInQuad','easeOutInCubic','easeOutInQuart','easeOutInQuint','easeOutInSine','easeOutInExpo','easeOutInCirc','easeOutInBack','easeOutInBounce',
]function createEasingDemo(easing) {var demoEl = document.createElement('div');demoEl.classList.add('el', 'square', 'stretched', 'easing-'+easing);anime({targets: demoEl,translateY: [50, -50],direction: 'alternate',loop: true,delay: 100,endDelay: 100,duration: 1000,easing: easing});fragment.appendChild(demoEl);
}easingNames.forEach(function(easeName) {createEasingDemo(easeName);
});demoContentEl.innerHTML = '';
demoContentEl.appendChild(fragment);
了解其他值可以访问这里,
duration: 持续时间 type: Number
delay: 延迟 type: Number || Object
endDelay: 最后延迟 type: Number || Object
round: 将动画值舍入为1位小数 type: Number
样式变化
CSS样式:大多数CSS都可以做动画
Transforms:
属性名 | 单位 |
---|---|
'translateX' | 'px' |
'translateY' | 'px' |
'translateZ' | 'px' |
'rotate' | 'deg' |
'rotateX' | 'deg' |
'rotateY' | 'deg' |
'rotateZ' | 'deg' |
'scale' | — |
'scaleX' | — |
'scaleY' | — |
'scaleZ' | — |
'skew' | 'deg' |
'skewX' | 'deg' |
'skewY' | 'deg' |
'perspective' | 'px' |
当目标值是Object时,他的变化主要是由属性自身引起的
properties Type:String||Object||function
如果值是func的话,他的参数将是下面这几个
ARGUMENTS | INFOS |
---|---|
target | The curent animated targeted element |
index | The index of the animated targeted element |
targetsLength | The total number of animated targets |
anime({targets: '.function-based-params-demo .el',translateX: 270,direction: 'alternate',loop: true,delay: function(el, i, l) {return i * 100;},endDelay: function(el, i, l) {return (l - i) * 100;}
});
1、计算
anime({targets: '.el.relative-values',translateX: {value: '*=2.5', // 100px * 2.5 = '250px'duration: 1000},width: {value: '-=20px', // 28 - 20 = '8px'duration: 1800,easing: 'easeInOutSine'},rotate: {value: '+=2turn', // 0 + 2 = '2turn'duration: 1800,easing: 'easeInOutSine'},direction: 'alternate'
});
2、范围:最终会在100到250之间移动
anime({targets: '.el.from-to-values',translateX: [100, 250], // from 100 to 250delay: 500,direction: 'alternate',loop: true
});
3、添加动画方式
var colorsExamples = anime.timeline({endDelay: 1000,easing: 'easeInOutQuad',direction: 'alternate',loop: true
})
.add({ targets: '.color-hex', background: '#FFF' }, 0)
.add({ targets: '.color-rgb', background: 'rgb(255,255,255)' }, 0)
.add({ targets: '.color-hsl', background: 'hsl(0, 100%, 100%)' }, 0)
.add({ targets: '.color-rgba', background: 'rgba(255,255,255, .2)' }, 0)
.add({ targets: '.color-hsla', background: 'hsla(0, 100%, 100%, .2)' }, 0)
.add({ targets: '.colors-demo .el', translateX: 270 }, 0);
anime({targets: '.property-keyframes-demo .el',translateX: [{ value: 250, duration: 1000, delay: 500 },{ value: 0, duration: 1000, delay: 500 }],translateY: [{ value: -40, duration: 500 },{ value: 40, duration: 500, delay: 1000 },{ value: 0, duration: 500, delay: 1000 }],scaleX: [{ value: 4, duration: 100, delay: 500, easing: 'easeOutExpo' },{ value: 1, duration: 900 },{ value: 4, duration: 100, delay: 500, easing: 'easeOutExpo' },{ value: 1, duration: 900 }],scaleY: [{ value: [1.75, 1], duration: 500 },{ value: 2, duration: 50, delay: 1000, easing: 'easeOutExpo' },{ value: 1, duration: 450 },{ value: 1.75, duration: 50, delay: 1000, easing: 'easeOutExpo' },{ value: 1, duration: 450 }],easing: 'easeOutElastic(1, .8)',loop: true
});
var animation = anime({});
//播放
animation.play()
//暂停
animation.pause()
var animation = anime({});
//重新开始
animation.restart()
var animation = anime({});
//倒退播放
animation.reverse()
var updates = 0;anime({targets: '.update-demo .el',translateX: 270,delay: 1000,direction: 'alternate',loop: 3,easing: 'easeInOutCirc',update: function(anim) {updates++;progressLogEl.value = 'progress : '+Math.round(anim.progress)+'%';updateLogEl.value = 'updates : '+updates;}
});
anime({targets: '.begin-complete-demo .el',translateX: 240,delay: 1000,easing: 'easeInOutCirc',update: function(anim) {progressLogEl.value = 'progress : ' + Math.round(anim.progress) + '%';beginLogEl.value = 'began : ' + anim.began;completeLogEl.value = 'completed : ' + anim.completed;},begin: function(anim) {beginLogEl.value = 'began : ' + anim.began;},complete: function(anim) {completeLogEl.value = 'completed : ' + anim.completed;}
});
var loopBegan = 0;
var loopCompleted = 0;anime({targets: '.loopBegin-loopComplete-demo .el',translateX: 240,loop: true,direction: 'alternate',easing: 'easeInOutCirc',loopBegin: function(anim) {loopBegan++;beginLogEl.value = 'loop began : ' + loopBegan;},loopComplete: function(anim) {loopCompleted++;completeLogEl.value = 'loop completed : ' + loopCompleted;}
});
var changes = 0;anime({targets: '.change-demo .el',translateX: 270,delay: 1000,endDelay: 1000,direction: 'alternate',loop: true,easing: 'easeInOutCirc',update: function(anim) {progressLogEl.value = 'progress : '+Math.round(anim.progress)+'%';},change: function() {changes++;changeLogEl.value = 'changes : ' + changes;}
});
var changeBegan = 0;
var changeCompleted = 0;anime({targets: '.changeBegin-chnageComplete-demo .el',translateX: 240,delay: 1000,endDelay: 1000,loop: true,direction: 'alternate',easing: 'easeInOutCirc',update: function(anim) {progressLogEl.value = 'progress : '+Math.round(anim.progress)+'%';},changeBegin: function(anim) {changeBegan++;beginLogEl.value = 'change began : ' + changeBegan;},changeComplete: function(anim) {changeCompleted++;completeLogEl.value = 'change completed : ' + changeCompleted;}
});
var progressLogEl = document.querySelector('.promise-demo .progress-log');
var promiseEl = document.querySelector('.promise-demo .el');
var finishedLogEl = document.querySelector('.promise-demo .finished-log');
var demoPromiseResetTimeout;function logFinished() {anime.set(finishedLogEl, {value: 'Promise resolved'});anime.set(promiseEl, {backgroundColor: '#18FF92'});
}var animation = anime.timeline({targets: promiseEl,delay: 400,duration: 500,endDelay: 400,easing: 'easeInOutSine',update: function(anim) {progressLogEl.value = 'progress : '+Math.round(anim.progress)+'%';}
}).add({translateX: 250
}).add({scale: 2
}).add({translateX: 0
});animation.finished.then(logFinished);