国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【Anime.js】——JavaScript動(dòng)畫庫:Anime.js——學(xué)習(xí)筆記

這篇具有很好參考價(jià)值的文章主要介紹了【Anime.js】——JavaScript動(dòng)畫庫:Anime.js——學(xué)習(xí)筆記。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

目錄

一、搭建開發(fā)環(huán)境

?二、基本功能和使用

開始制作動(dòng)畫

動(dòng)畫屬性

三、anime.stagger——交錯(cuò)動(dòng)畫

四、timeline——時(shí)間軸

?五、控制、回調(diào)與助手

一、控制

?二、回調(diào)

三、助手

六、easings——?jiǎng)赢嬤\(yùn)動(dòng)曲線

七、SVG動(dòng)畫


官網(wǎng)定義:

anime.js 是一個(gè)簡便的JS動(dòng)畫庫,用法簡單而且適用范圍廣,涵蓋CSS,DOM,SVG還有JS的對象,各種帶數(shù)值屬性的東西都可以動(dòng)起來。

一、搭建開發(fā)環(huán)境

1、新建一個(gè)文件夾 ,用vs?code打開,將其添加到工作區(qū)。

anime.js,前端,javascript,前端,html

2、打開終端

anime.js,前端,javascript,前端,html

在終端輸入:

npm i animejs --save

anime.js,前端,javascript,前端,html

?3、創(chuàng)建文件夾,使用anime.js包

anime.js,前端,javascript,前端,html

anime.js,前端,javascript,前端,html位置如圖。

4、實(shí)現(xiàn)一個(gè)簡易的動(dòng)畫樣式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            background-color: brown;
        }
    </style>
</head>
<body>
    <div></div>
    <script src="node_modules/animejs/lib/anime.min.js"></script>
    <script>
        anime({
            targets:'div',
            translateX:'400px',
            easing:'linear',
            duration:2000
        })
    </script>
</body>
</html>

?就能實(shí)現(xiàn)一個(gè)方塊勻速運(yùn)動(dòng)的效果了。anime.js,前端,javascript,前端,html

?二、基本功能和使用

anime.js,前端,javascript,前端,html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            background-color: blueviolet;
        }
    </style>
</head>
<body>
    <div id = 'first'></div>
    <div class = 'second'></div>
    <div class = 'second'></div>
    <div class = 'second'></div>
    <script src="../node_modules/animejs/lib//anime.min.js"></script>
    <script>
        anime({
            targets:'#first',
            translateX:'400px'
        })
    </script>
</body>
</html>

?第一個(gè)div動(dòng):anime.js,前端,javascript,前端,html

?如果把代碼改成這樣:

 <script>
        anime({
            targets:'.second',
            translateX:'400px'
        })
 </script>

anime.js,前端,javascript,前端,html

?可以看到,targets用來作為選擇器來選擇移動(dòng)元素。?

開始制作動(dòng)畫

anime({
targets: 'div',
translateX: [
    { value: 100, duration: 1200 },
    { value: 0, duration: 800 }
],
rotate: '1turn',
backgroundColor: '#FFF',
duration: 2000,
loop: true
});

targets屬性定義了制作動(dòng)畫的元素或js對象:

  • css選擇器 如:'div','#el path';
  • DOM元素 如: document.querySelector('.item')
  • 節(jié)點(diǎn)列表 如: document.querySelectorAll('.item')
  • 對象
  • 數(shù)組 如:['div', '.item', domNode]

動(dòng)畫屬性

1、CSS:

  • opacity 透明度 0~1
  • backgroundColor
  • fontSize
  • borderRadius
  • backgroundColor

2、transforms變換:

  • translateX x軸的值
  • translateY y軸的值
  • retate 旋轉(zhuǎn)
  • scale 大小變換 例:scale:2? ?scale:0.5? ?
  • rotate 旋轉(zhuǎn) 例:rotate:'1turn'(旋轉(zhuǎn)一周)

3、對象屬性

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: cadetblue;
        }
    </style>
</head>

<body>
    <div id="JSobjectProp">
        <span>{"myProperty":"0"}</span>
    </div>
    <script src="../node_modules/animejs/lib//anime.min.js"></script>
    <script>
        var myObject = {
            prop1: 0,
            prop2: '0%'
        }
        var JSobjectProp = anime({
            targets: myObject,
            prop1: 50,
            prop2: '100%',
            easing: 'linear',
            round: 1,
            update: function () {
                var el = document.querySelector('#JSobjectProp span');
                el.innerHTML = JSON.stringify(myObject);
            }
        });
    </script>
</body>

</html>

開始:?

?anime.js,前端,javascript,前端,html

?變?yōu)椋?/p>

anime.js,前端,javascript,前端,html4、DOM屬性

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    </style>
</head>

<body>
    <input class="text-output" value="0">
    <script src="../node_modules/animejs/lib//anime.min.js"></script>
    <script>
        var domAttributes = anime({
            targets: 'input',
            value: 1000, // value變化為1000
            round: 100, //表示小數(shù),把1分成了100份,也就是展示兩位小數(shù)點(diǎn)
            easing: 'easeInOutExpo'
        });
    </script>
</body>

</html>

anime.js,前端,javascript,前端,html

?5、給每個(gè)屬性單獨(dú)設(shè)置

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: cadetblue;
        }
    </style>
</head>
<body>
    <div></div>
    <script src="../node_modules/animejs/lib//anime.min.js"></script>
    <script>
        anime({
                targets: 'div',
                translateX: {
                    value: 250,//通過value來設(shè)置值
                    duration: 800 //表示延長動(dòng)畫效果的時(shí)間
                },
                rotate: {
                    value: 360,
                    duration: 1800,
                    easing: 'easeInOutSine'
                },
                scale: {
                    value: 2,
                    duration: 1600,
                    delay: 800,
                    easing: 'easeInOutQuart'
                },
                delay: 250 // All properties except 'scale' inherit 250ms delay
            });
    </script>
</body>
</html>

?6、屬性參數(shù)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: cadetblue;
        }
    </style>
</head>

<body>
    <div></div>
    <script src="../node_modules/animejs/lib//anime.min.js"></script>
    <script>
        anime({
            targets: 'div',
            translateX: 270,
            direction: 'alternate',
            loop: true,
            // 接收三個(gè)參數(shù):
            // el:表示當(dāng)前目標(biāo)元素
            // i: 表示當(dāng)前目標(biāo)元素下標(biāo)
            // l:表示目標(biāo)元素的總長度
            delay: function (el, i, l) {
                return i * 100;
            },
            endDelay: function (el, i, l) {
                return (l - i) * 100;
            }

        });
    </script>
</body>

</html>

三、anime.stagger——交錯(cuò)動(dòng)畫

1、

anime.stagger(value, options)
//它針對多個(gè)元素。
//第一個(gè)參數(shù)接收:Number, String, Array
//第二個(gè)參數(shù)接收:Object
anime({
  targets: '.basic-staggering-demo .el',
  translateX: 270,
  delay: anime.stagger(100) // increase delay by 100ms for each elements.
});

anime.js,前端,javascript,前端,html

anime.js,前端,javascript,前端,html

效果:?

?anime.js,前端,javascript,前端,html

2、?

anime.stagger(value, {start: startValue}) //在value后面添加對象屬性

?anime.js,前端,javascript,前端,html

anime({
  targets: '.staggering-start-value-demo .el',
  translateX: 270,
  delay: anime.stagger(100, {start: 500}) // delay starts at 500ms then increase by 100ms for each elements.
});

3、

anime.stagger([startValue, endValue]) //作為rotate旋轉(zhuǎn)的屬性值
anime({
  targets: '.range-value-staggering-demo .el',
  translateX: 270,
  rotate: anime.stagger([-360, 360]), // rotation will be distributed from -360deg to 360deg evenly between all elements
  easing: 'easeInOutQuad'
});

anime.js,前端,javascript,前端,html

?4、

anime.stagger(value, {from: startingPosition}) //從哪個(gè)位置依次延遲
anime({
  targets: '.staggering-from-demo .el',
  translateX: 270,
  delay: anime.stagger(100, {from: 'center'})
});

5、

anime.stagger(value, {direction: 'reverse'}) //反向延遲
anime({
  targets: '.staggering-direction-demo .el',
  translateX: 270,
  delay: anime.stagger(100, {direction: 'reverse'})
});

6、

anime.stagger(value, {grid: [rows, columns]})
anime({
  targets: '.staggering-grid-demo .el',
  scale: [
    {value: .1, easing: 'easeOutSine', duration: 500},
    {value: 1, easing: 'easeInOutQuad', duration: 1200}
  ],
    //grid: [14, 5]表示14行5列
    //from 表示從哪里開始
  delay: anime.stagger(200, {grid: [14, 5], from: 'center'})
});

anime.js,前端,javascript,前端,html

7、

anime.stagger(value, {grid: [rows, columns], axis: 'x'})
//axis設(shè)置為x,表示將一整行設(shè)置為整體
//設(shè)為y,會將一整列設(shè)置為整體
anime({
  targets: '.staggering-axis-grid-demo .el',
  translateX: anime.stagger(10, {grid: [14, 5], axis: 'x'})
})

anime.js,前端,javascript,前端,html?anime.js,前端,javascript,前端,html

四、timeline——時(shí)間軸

接下來學(xué)習(xí)官網(wǎng)的時(shí)間軸模塊。

anime.js,前端,javascript,前端,html

?這個(gè)模塊告訴我們可以創(chuàng)建一個(gè)時(shí)間軸,在這個(gè)時(shí)間軸上可以創(chuàng)建多個(gè)動(dòng)畫,并且添加在時(shí)間軸上的每一個(gè)動(dòng)畫都會在上一個(gè)動(dòng)畫結(jié)束之后開始執(zhí)行。

1、創(chuàng)建時(shí)間軸

創(chuàng)建一個(gè)時(shí)間軸:

//調(diào)用該方法:
var myTimeline = anime.timeline(parameters);

如何通過這個(gè)時(shí)間軸調(diào)用對象:

myTimeline.add(parameters, offset);
//parameters 動(dòng)畫相關(guān)的參數(shù)
//offset 時(shí)間偏移量

實(shí)例:?

// 創(chuàng)建了一個(gè)時(shí)間軸對象
var tl = anime.timeline({
  easing: 'easeOutExpo',
  duration: 750  // 持續(xù)時(shí)間是750ms
});

// 時(shí)間軸上分別創(chuàng)建了三個(gè)動(dòng)畫
tl
.add({
  targets: '.basic-timeline-demo .el.square', //方形
  translateX: 250,   // 平移250px
})
.add({
  targets: '.basic-timeline-demo .el.circle', //圓形
  translateX: 250,
})
.add({
  targets: '.basic-timeline-demo .el.triangle', //三角形
  translateX: 250,
});

anime.js,前端,javascript,前端,html

anime.js,前端,javascript,前端,html

?會等到上一個(gè)方塊執(zhí)行完,才會執(zhí)行圓。

2、時(shí)間偏移量

?時(shí)間偏移量是我們創(chuàng)建時(shí)間軸的第二個(gè)參數(shù)。

默認(rèn)情況下,每一個(gè)動(dòng)畫都會在上一個(gè)動(dòng)畫結(jié)束之后開始執(zhí)行,通過時(shí)間偏移量就可以改變每個(gè)動(dòng)畫開始執(zhí)行的時(shí)間。

如下圖可以看到,時(shí)間偏移量可以有兩種數(shù)據(jù)類型:String字符串、Number數(shù)字

anime.js,前端,javascript,前端,html

?字符串是相對于上一個(gè)動(dòng)畫的設(shè)置的,比如:

'+=200'表示:是上一個(gè)動(dòng)畫執(zhí)行結(jié)束完200ms后再執(zhí)行當(dāng)前的動(dòng)畫

'-=200'表示:是上一個(gè)動(dòng)畫執(zhí)行結(jié)束前200ms后執(zhí)行當(dāng)前的動(dòng)畫

數(shù)字偏移量是相對于整個(gè)時(shí)間軸的絕對偏移量。

200表示:當(dāng)前時(shí)間軸開始200ms后執(zhí)行。

// Create a timeline with default parameters
var tl = anime.timeline({
  easing: 'easeOutExpo',
  duration: 750
});

tl
.add({
  targets: '.offsets-demo .el.square',
  translateX: 250,
})
.add({
  targets: '.offsets-demo .el.circle',
  translateX: 250,
}, '-=600') // 相對偏移量————字符創(chuàng)
.add({
  targets: '.offsets-demo .el.triangle',
  translateX: 250,
}, 400); // 絕對偏移量————數(shù)字

3、參數(shù)繼承

添加在時(shí)間軸中的動(dòng)畫,都可以繼承表格里的這些屬性
targets
easing
duration
delay
endDelay
round

注意:

direction 和 loop 是不可以被繼承的。

演示:(繼承targets屬性)?

anime.js,前端,javascript,前端,html

anime.js,前端,javascript,前端,html?

?五、控制、回調(diào)與助手

一、控制

頁面中需要的元素:

anime.js,前端,javascript,前端,html

anime.js,前端,javascript,前端,html

?1、動(dòng)畫上的屬性

animation.play(); //開始
animation.pause(); //暫停
animation.restart(); //重新開始
animation.reverse(); //反向移動(dòng)
// seek 當(dāng)前元素顯示在具體時(shí)間的某一幀
// timeStamp:跳到具體的時(shí)間
animation.seek(timeStamp); 
// 通過滾動(dòng)條來控制動(dòng)畫
// scrollPercent / 100:求滾動(dòng)條的百分比
// animation.duration:當(dāng)前動(dòng)畫的時(shí)間
// (scrollPercent / 100) * animation.duration:具體跳到的時(shí)間值
animation.seek((scrollPercent / 100) * animation.duration);

anime.js,前端,javascript,前端,html?anime.js,前端,javascript,前端,html

?2、時(shí)間軸上的屬性

//?控制時(shí)間軸上的動(dòng)畫:
timeline.play();
timeline.pause();
timeline.restart();
timeline.seek(timeStamp);

anime.js,前端,javascript,前端,html

?二、回調(diào)

?1、UPDATE:每更新一幀就會調(diào)用一次

var updates = 0;

anime({
  targets: '.update-demo .el',
  translateX: 270,
  delay: 1000,
  direction: 'alternate',
  loop: 3,
  easing: 'easeInOutCirc',
    // anim當(dāng)前動(dòng)畫的實(shí)例
  update: function(anim) {
    updates++;
    // anim.progress 當(dāng)前動(dòng)畫的進(jìn)度
    progressLogEl.value = 'progress : '+Math.round(anim.progress)+'%';
    updateLogEl.value = 'updates : '+updates;
  }
});

示例:?

anime.js,前端,javascript,前端,html

anime.js,前端,javascript,前端,html

?表示更新了58幀。

2、BEGIN & COMPLETE

BEGIN:動(dòng)畫開始執(zhí)行前觸發(fā)一次

COMPLETE:動(dòng)畫結(jié)束時(shí)觸發(fā)一次

? ? ? ? 這兩個(gè)屬性是布爾類型

示例:

anime.js,前端,javascript,前端,html

注意箭頭處的寫法是不一樣的?。。?/p>

?效果:anime.js,前端,javascript,前端,html

?3、LOOPBEGIN & LOOPCOMPLETE

LOOPBEGIN:循環(huán)開始時(shí)就會觸發(fā)一次

LOOPCOMPLETE:循環(huán)結(jié)束時(shí)就會觸發(fā)一次

注意:動(dòng)畫一定是循環(huán)的動(dòng)畫

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;
  }
});

4、CHANGE:動(dòng)畫元素每更新一次就調(diào)用一次

與update的區(qū)別:change在delay和endDelay期間是不更新的,update反之。

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;
  }
});

?5、FINISHED PROMISE:每一個(gè)動(dòng)畫實(shí)例完成都會返回一個(gè)promise

// animation表示創(chuàng)建的動(dòng)畫實(shí)例
animation.finished.then(function() {
  // Do things...
});
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);

三、助手

1、anime.remove

// remove 將某個(gè)targets對象移出
anime.remove(targets);
animation.remove(targets);
var animation = anime({
  targets: '.remove-demo .el',
  translateX: 270,
  direction: 'alternate',
  loop: true,
  easing: 'easeInOutQuad'
});

document.querySelector('.remove-el-button').addEventListener('click', function() {
  animation.remove('.remove-demo .line:nth-child(2) .el');
});

2、anime.get

// get 獲取元素的信息
// target 獲取的元素
// propertyName 獲取的元素的屬性
// unit 單位
anime.get(target, propertyName, unit);
var logEl = document.querySelector('.get-value-demo-log');
var el = document.querySelector('.get-value-demo .el');

logEl.innerHTML = '';
logEl.innerHTML += '".el" width is :<br>';
logEl.innerHTML += '"' + anime.get(el, 'width', 'px') + '"';
logEl.innerHTML += ' or "' + anime.get(el, 'width', 'rem') + 'rem"'

3、anime.set

// set 設(shè)置元素的屬性值是什么
// {property: value} :是一個(gè)對象,{屬性:值}
// target(s) 類型是'string', var
// value 類型是object
anime.set(targets, {property: value});
anime.set('.set-value-demo .el', {
  translateX: function() { return anime.random(50, 250); },
  rotate: function() { return anime.random(0, 360); },
});

4、anime.random

// random 返回一個(gè)隨機(jī)數(shù)
anime.random(minValue, maxValue);
function randomValues() {
  anime({
    targets: '.random-demo .el',
    translateX: function() {
      return anime.random(0, 270);
    },
    easing: 'easeInOutQuad',
    duration: 750,
    complete: randomValues
  });
}

randomValues();

5、anime.running

//running 表示動(dòng)畫實(shí)例,其長度代表動(dòng)畫個(gè)數(shù)
anime.running
var runninLogEl = document.querySelector('.running-log');

anime({
  targets: '.running-demo .square.el',
  translateX: 270,
  direction: 'alternate',
  loop: true,
  easing: 'linear'
});

anime({
  targets: '.running-demo .circle.el',
  translateX: 270,
  direction: 'alternate',
  loop: true,
  easing: 'easeInOutCirc'
});

anime({
  targets: '.running-demo .triangle.el',
  translateX: 270,
  direction: 'alternate',
  easing: 'easeInOutQuad',
  loop: true,
  update: function() {
    runninLogEl.innerHTML = 'there are currently ' + anime.running.length + ' instances running';
  }
});

六、easings——?jiǎng)赢嬤\(yùn)動(dòng)曲線

1、使用

// linear表示線性
easing: 'linear'

2、方法

查看這些方法是如何的變化

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'

舉例:

anime.js,前端,javascript,前端,html

?3、BéZIER曲線和spring彈簧

二者都是參數(shù)改變變化的曲線

// 方法接收4個(gè)參數(shù),通過參數(shù)來改變運(yùn)動(dòng)曲線
easing: 'cubicBezier(.5, .05, .1, .3)'
// mass 質(zhì)量
// stiffness 高度
// damping 阻尼
// velocity 速度
easing: 'spring(mass, stiffness, damping, velocity)'
屬性 默認(rèn)值 MIN MAX
Mass 1 0 100
Stiffness 100 0 100
Damping 10 0 100
Velocity 0 0 100

4、ELASTIC

// amplitude 振幅
// period 來回的次數(shù)
// 也是表示彈簧,只不過彈的方向不一樣
easing: 'easeOutElastic(amplitude, period)'
IN OUT IN-OUT OUT-IN
'easeInElastic' 'easeOutElastic' 'easeInOutElastic' 'easeOutInElastic'
屬性 默認(rèn)值 MIN MAX
Amplitude 1 1 10
Period .5 0.1 2

5、跳動(dòng)

// numberOfSteps跳動(dòng)的步數(shù)
easing: 'steps(numberOfSteps)'
屬性 默認(rèn)值 MIN MAX
Number of steps 10 1

6、自定義函數(shù)

easing: function() { return function(time) { return time * i} }

注意返回的一定是個(gè)函數(shù)

anime({
  targets: '.custom-easing-demo .el',
  translateX: 270,
  direction: 'alternate',
  loop: true,
  duration: 2000,
  easing: function(el, i, total) {
    return function(t) {
      return Math.pow(Math.sin(t * (i + 1)), total);
    }
  }
});

七、SVG動(dòng)畫

1、運(yùn)動(dòng)

// svg path 表示svg的路徑
var myPath = anime.path('svg path');

// myPath 接收三個(gè)參數(shù)
// myPath('x'),傳入的是svg path中 x 的值
// myPath('y'),傳入的是svg path中 y 的值
// myPath('angle'),傳入的是svg path中 角度 的值
var path = anime.path('.motion-path-demo path');

anime({
  targets: '.motion-path-demo .el',
  translateX: path('x'),
  translateY: path('y'),
  rotate: path('angle'),
  easing: 'linear',
  duration: 2000,
  loop: true
});

示例:

anime.js,前端,javascript,前端,html

anime.js,前端,javascript,前端,html

?效果:

anime.js,前端,javascript,前端,html

?2、變形

給大家分享一個(gè)svg的繪制編輯器網(wǎng)頁:

svg編輯器

anime.js,前端,javascript,前端,html

anime.js,前端,javascript,前端,html?效果:就可以在頁面看到動(dòng)態(tài)的五邊形

anime.js,前端,javascript,前端,html

?3、劃線

首先要有一個(gè)畫好的svg的線,然后通過:

strokeDashoffset: [anime.setDashoffset, 0]

?來實(shí)現(xiàn)劃線。

anime.js,前端,javascript,前端,html

anime.js,前端,javascript,前端,html?效果:

anime.js,前端,javascript,前端,html


筆記參考:https://www.jianshu.com/p/39fc8a837b31?

官方文檔:https://animejs.com/documentation/#functionBasedParameters文章來源地址http://www.zghlxwxcb.cn/news/detail-790172.html

到了這里,關(guān)于【Anime.js】——JavaScript動(dòng)畫庫:Anime.js——學(xué)習(xí)筆記的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • HTML+CSS+JS 學(xué)習(xí)筆記(三)———Javascript(中)

    HTML+CSS+JS 學(xué)習(xí)筆記(三)———Javascript(中)

    ??博客主頁:大寄一場. ??系列專欄:前端 ??往期回顧:HTML+CSS+JS 學(xué)習(xí)筆記(三)———Javascript(上) ??博客制作不易歡迎各位??點(diǎn)贊+?收藏+?關(guān)注 目錄 ?JavaScript中的函數(shù) 函數(shù)的定義和調(diào)用 函數(shù)的定義 ?函數(shù)的調(diào)用 嵌套函數(shù) ?遞歸函數(shù) ?變量的作用域 全局變量和局部

    2024年02月06日
    瀏覽(27)
  • 【JavaEE初階】前端第四節(jié).JavaScript入門學(xué)習(xí)筆記

    【JavaEE初階】前端第四節(jié).JavaScript入門學(xué)習(xí)筆記

    作者簡介:大家好,我是未央; 博客首頁:未央.303 系列專欄:Java測試開發(fā) 每日一句:人的一生,可以有所作為的時(shí)機(jī)只有一次,那就是現(xiàn)在?。。?前言 一、前置知識? 1、JS?和 HTML 和 CSS 之間的關(guān)系 1.2?JS 的書寫形式 1.2.1 內(nèi)嵌式 1.2.2?行內(nèi)式? 1.2.3?外部式 1.2.4?擴(kuò)展 1.2

    2024年02月08日
    瀏覽(19)
  • jQuery.js - 前端必備的Javascript庫

    jQuery.js - 前端必備的Javascript庫

    作者: WangMin 格言: 努力做好自己喜歡的每一件事 jQuery.js 是什么? jQuery是一個(gè)快速簡潔、免費(fèi)開源易用的JavaScript框架, 倡導(dǎo)寫更少的代碼,做更多的事情 。它封裝JavaScript常用的功能代碼,提供了一種簡便的JavaScript設(shè)計(jì)模式,以及我們開發(fā)中常用到的操作DOM的API,優(yōu)化HTML文

    2024年02月05日
    瀏覽(90)
  • web前端框架JS學(xué)習(xí)之JavaScript類型轉(zhuǎn)換

    web前端框架JS學(xué)習(xí)之JavaScript類型轉(zhuǎn)換

    vascript有多種數(shù)據(jù)類型,如字符串、數(shù)字、布爾等,可以通過typeof語句來查看變量的數(shù)據(jù)類型。數(shù)據(jù)類型轉(zhuǎn)換就是數(shù)據(jù)類型之間相互轉(zhuǎn)換,比如把數(shù)字轉(zhuǎn)成字符串、把布爾值轉(zhuǎn)成字符串、把字符串轉(zhuǎn)成數(shù)字等,這在工作也是經(jīng)常碰到的。 本期我們就給大家說說web前端框架JS學(xué)

    2024年02月10日
    瀏覽(89)
  • 前端進(jìn)化筆記-JavaScript(三)

    人類在白色的底色上描繪圖畫,地球在黑色的底色上創(chuàng)造生命。 JavaScript的變量可以說是獨(dú)樹一幟。只需要一個(gè)(或兩個(gè)等)(const,let)就可以創(chuàng)建變量,創(chuàng)建時(shí)不考慮變量的類型,這是其他語言少有的強(qiáng)大功能。當(dāng)然強(qiáng)大的功能總是伴隨著問題。 原始值:Undefined,

    2024年02月08日
    瀏覽(25)
  • 【前端靈魂腳本語言JavaScript⑤】——JS中數(shù)組的使用

    【前端靈魂腳本語言JavaScript⑤】——JS中數(shù)組的使用

    ?? 作者: 阿偉 ?? 個(gè)人主頁: Flyme awei ?? 希望大家多多支持??一起進(jìn)步呀! ?? 文章對你有幫助??關(guān)注?點(diǎn)贊??收藏?? 第一種: var 數(shù)組名 = new Array(); 創(chuàng)建一個(gè)空數(shù)組 第二種: var arr2 = new Array(10); 創(chuàng)建一個(gè)定長為10的數(shù)組 第三種 var arr3 = new Array(a,b,c); 創(chuàng)建時(shí)直接指定元素值

    2023年04月08日
    瀏覽(111)
  • Web前端 Javascript筆記3

    Web前端 Javascript筆記3

    ?內(nèi)存中的生命周期 ? ? ? ? 1、內(nèi)存分配 ? ? ? ? 2、內(nèi)存使用(讀寫) ? ? ? ? 3、內(nèi)存回收,使用完畢之后,垃圾回收器完成 ? ? ? ? 內(nèi)存泄漏:該回收的,由于某些未知因素,未釋放,叫做內(nèi)存泄漏 棧:數(shù)據(jù)存在其中會自動(dòng)釋放 堆:對象,根據(jù)程序員的操作來決定釋

    2024年04月15日
    瀏覽(28)
  • 〖大前端 - 基礎(chǔ)入門三大核心之JS篇?〗- JavaScript 的「數(shù)組」

    〖大前端 - 基礎(chǔ)入門三大核心之JS篇?〗- JavaScript 的「數(shù)組」

    當(dāng)前子專欄 基礎(chǔ)入門三大核心篇 是免費(fèi)開放階段 。 推薦他人訂閱,可獲取扣除平臺費(fèi)用后的35%收益,文末名片加V! 說明:該文屬于 大前端全棧架構(gòu)白寶書專欄, 目前階段免費(fèi)開放 , 購買任意白寶書體系化專欄可加入 TFS-CLUB 私域社區(qū)。 福利:除了通過訂閱\\\"白寶書系列專

    2024年02月04日
    瀏覽(23)
  • web前端javaScript筆記——(11)DOM

    屬性 ????????????????????????????????????此事件發(fā)生在何時(shí) onabort 圖像的加載被中斷。 onblur???????????????????????????????????元素失去焦點(diǎn)。 anchange?????????????????????????????????域的內(nèi)容被改變 onclick ?當(dāng)用戶點(diǎn)擊某

    2024年01月19日
    瀏覽(27)
  • web前端javascript筆記——(13)事件(1)

    鼠標(biāo)/鍵盤屬性 altKey???????????????返回當(dāng)事件被觸發(fā)時(shí),“ALT”是否被按下。 button???????????????返回當(dāng)事件被觸發(fā)時(shí),哪個(gè)鼠標(biāo)按鈕被點(diǎn)擊 clientX???????????????返回當(dāng)事件被觸發(fā)時(shí),鼠標(biāo)指針的水平坐標(biāo)。 clientY???????????????返回當(dāng)事件被觸

    2024年01月25日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包