5.12 練習
練習 1: cubic-bezier
透過這個網站,拉一個效果,如下結果示意。
指定檔名:cubic_bezier.html
提供 html:
<div class="outer_block">
<div class="block">div 區塊</div>
</div>
<button type="button" class="trigger">觸發</button>提供部份 css:
* {
box-sizing: border-box;
}
body{
margin: 0;
}
div.outer_block{
width: 500px;
height: 100px;
border: 1px solid black;
position: relative;
margin-left: 100px;
margin-top: 100px;
}
div.block{
border: 1px solid blue;
display: inline-block;
width: 100px;
height: 98px;
position: absolute;
left: 0;
top: 0;
}提供 js:
結果示意:
參考作法:
練習 2:左右擺動
指定檔名:button_wiggle.html
@keyframes 說明:
動畫效果名稱為
wiggle0% 時的位置:
left: 0;10% 時的位置:
left: -10px;20% 時的位置:
left: 0;30% 時的位置:
left: 10px;40% 時的位置:
left: 0;50% 時的位置:
left: -10px;60% 時的位置:
left: 0;70% 時的位置:
left: 10px;100% 時的位置:
left: 0;
其它說明:
動畫效果執行一次(
animation-duration)的時間為 1s漸變函式(
animation-timing-function)設定為 linearinput.input_text 元素的 position 設定為 relative
提供 html:
提供部份 css:
提供 js(放在 </body> 結束標籤之前):
結果示意:
參考作法:
練習 3:Sprite 效果
指定檔名:animation_sprite.html
圖片路徑: https://alldata.sgp1.digitaloceanspaces.com/images/sprite_img_new.png
說明:
此圖的寬高分別是
850px、170px。animation-timing-function使用steps函式。執行方向:做一個寬高都是 170px 的 div,搭配 animation 動畫效果。
提供 html:
結果示意:
參考作法:
背景圖做法:
1、算出每跳一次,要多少百分比 → 25%。
2、steps 要 5 個間隔,就 25% * 5 = 125%。
img 標籤做法:
Last updated