自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

HarmonyOS - 實現(xiàn)電動小風扇

系統(tǒng) OpenHarmony
這篇文章是我對學習鴻蒙動畫API的一個練習,也算是一個比較常見的動畫。

??想了解更多關于開源的內容,請訪問:??

??51CTO 開源基礎軟件社區(qū)??

??https://ost.51cto.com??

前言

隨著氣溫越來越高,相信很多小伙伴已經沒有心思工作了,作為前端的開發(fā)人員,決定自己搞個風扇降將溫。剛好最近在學習HarmonyOS開發(fā)相關知識,發(fā)現(xiàn)動畫屬性使用比較多并且學起來比較有意思,因此利用HarmonyOS的動畫效果實現(xiàn)了一個變速小風扇。

項目說明

  • 工具版本:DevEco Studio 3.0 Beta3
  • SDK版本;3.1.5.5
  • 主要用到知識:animate
  • 官方API鏈接:??動畫效果??

效果展示

#夏日挑戰(zhàn)賽# HarmonyOS - 實現(xiàn)電動小風扇-開源基礎軟件社區(qū)

實現(xiàn)原理

拆過電風扇的小伙伴應該知道,核心就是一個扇葉、控制開關、風扇罩,其余的都是些裝飾品。 首先,我們來實現(xiàn)我們的風扇罩和扇葉,這個功能比較簡單好實現(xiàn),無非就是CSS3中的一些特性,例如圓角呀、旋轉呀等等特性。 加上基于動畫animation相關知識,通過按鈕控制對扇葉進行相應的動畫效果處理,最終呈現(xiàn)出不同速度下不同風速的轉動效果。

實現(xiàn)步驟

  1. 對風扇樣式進行繪制(扇葉,扇柄,控制按鈕)
  2. 在觸發(fā)風速按鈕后,通過獲取風頁id屬性標識后,給該id對象調用動畫方法。
  3. 給1、2、3級風速傳入不同的所需轉動時長,實現(xiàn)低中高風速旋轉
  4. 判斷觸發(fā)關閉按鈕時,調用animation對象方法finish(),實現(xiàn)暫停風速的功能。

使用到的官方API

animate( keyframes: Keyframes, options: Options):void。

參數(shù)名

參數(shù)類型

必填

描述

keyframes

keyframes

設置動畫樣式

options

Options

用于設置動畫屬性的對象列表

keyframes:

屬性

類型

說明

frames

Array<Style>

用于設置動畫樣式的對象列表。

Style類型說明

參數(shù)

類型

默認值

說明

transform

??Transform??

-

設置到變換對象上的類型。

Options說明:

參數(shù)

類型

默認值

說明

duration

number

0

指定當前動畫的運行時長(單位毫秒)。

easing

string

linear

描述動畫的時間曲線,支持類型見表4 easing有效值說明。

delay

number

0

設置動畫執(zhí)行的延遲時間(默認值表示無延遲)。

iterations

number | string

1

設置動畫執(zhí)行的次數(shù)。number表示固定次數(shù),Infinity枚舉表示無限次數(shù)播放。

animation對象方法:

方法

參數(shù)

說明

play

-

組件播放動畫。

finish

-

組件完成動畫。

pause

-

組件暫停動畫。

cancel

-

組件取消動畫。

reverse

-

組件倒播動畫。

代碼實現(xiàn)

1、hml部分

<div class="container">
<div class="title">
<!--風扇葉上的裝飾線-->
<div class="line-box">
<div class="line"></div>
<div class="line line1"></div>
<div class="line line2"></div>
<div class="line line3"></div>
<div class="line line4"></div>
<div class="line line5"></div>
</div>
<!--扇葉-->
<div class="left-box" id="controlLevel" >
<text class="leaf"></text>
<text class="leaf leaf1"></text>
<text class="leaf leaf2"></text>
</div>
</div>
<!--扇柄-->
<div class="bom-part">
<text class="item" @click="oneLevel(900)" >1</text>
<text class="item" @click="oneLevel(750)">2</text>
<text class="item" @click="oneLevel(600)">3</text>
<text class="item" @click="oneLevel(4)"></text>
</div>
<!-- 風扇-->
<text class="base">變速小風扇</text>
</div>

2. css部分

.container {
flex-direction: column;
align-items: center;
width: 100%;
height: 100%;
}
.title {
width: 200px;
height: 200px;
margin-top: 150px;
position: relative;
font-size: 40px;
opacity: 0.9;
z-index: 200;
}
.line-box{
z-index:100;
}
.line{
position: absolute;
top: 48.8%;
left: 0px;
width: 200px;
height: 5px;
height: 5px;
background-color: black;
opacity: 0.75;
z-index: 100;
}
.line1{
transform: rotate(30deg);
}
.line2{
transform: rotate(60deg);
}
.line3{
transform: rotate(90deg);
}
.line4{
transform: rotate(120deg);
}
.line5{
transform: rotate(150deg);
}
.left-box{
width: 220px;
height: 220px;
border-radius: 110px;
border: 8px solid #333;
}
.leaf{
position: absolute;
left: 44%;
width: 30px;
height: 95px;
border-radius: 80px;
background-color: cornflowerblue;
}
.leaf1 {
height: 92px;
transform: rotate(125deg);
transform-origin: 50% 100%;
}
.leaf2 {
transform: rotate(240deg);
transform-origin: 50% 100%;
}
.bom-part{
width: 30px;
height: 200px;
background-color:black;
opacity: 0.75;
flex-direction:column;
position: absolute;
top: 348px;
left: 47%;
}
.item{
font-size: 16px;
text-align: center;
color: black;
width: 25px;
height: 25px;
border-radius:12.5px;
background-color: cornflowerblue;
margin-top: 10px;
margin-left: 3px;
}
.base{
width: 100%;
margin: 0 16px ;
height: 75px;
background-color: cornflowerblue;
position: absolute;
top: 575px;
color: black;
border-radius: 20px;
text-align: center;
}

3. js部分

export default {
data: {
animation:'',
},
// 觸發(fā)風速按鈕后,通過獲取風頁id屬性標識后,給該id對象調用動畫方法
oneLevel(value){
var options = {
easing:'linear',//描述動畫的時間曲線
duration: value,//指定當前動畫的運行時長(單位毫秒)
fill: 'forwards',//指定動畫開始和結束的狀態(tài)
iterations:'Infinity',//設置動畫執(zhí)行的次數(shù)
};
//用于設置動畫樣式的對象列表
var frames = [
{
transform: {
rotate: '0deg'
}
},
{
transform: {
rotate: '360deg'
}
}
];
// 給風頁添加動畫方法
this.animation = this.$element('controlLevel').animate(frames, options);
// 點擊關機時調用animation對象方法finish完成動畫實現(xiàn)停止風扇轉動功能
if(value==4){
this.animation.finish()
}else{
this.animation.play();
}

}
}

總結

這篇文章是我對學習鴻蒙動畫API的一個練習,也算是一個比較常見的動畫,后面還需繼續(xù)努力,希望和大家一起共同成長。

??想了解更多關于開源的內容,請訪問:??

??51CTO 開源基礎軟件社區(qū)??

??https://ost.51cto.com??。

責任編輯:jianghua 來源: 鴻蒙社區(qū)
相關推薦

2022-03-29 11:28:24

HarmonyOS動畫css

2022-07-20 15:24:47

ArkUI動畫效果項目開發(fā)

2023-05-09 07:42:45

顯卡風扇熱管

2021-10-20 15:49:12

風扇顯卡散熱

2021-08-31 15:42:43

技術研發(fā)充電

2017-04-13 09:56:57

0分貝主機風扇

2010-07-15 09:19:23

機房散熱

2022-04-20 20:47:35

圖像壓縮鴻蒙操作系統(tǒng)

2019-01-28 19:30:15

Windows 10風扇速度BIOS

2020-05-29 22:11:30

模式風扇性能

2010-04-30 09:37:07

Ubuntu 10.0GRUB2

2023-06-12 10:21:50

物聯(lián)網(wǎng)IoT

2022-12-27 17:57:03

開源汽車充電

2013-11-12 09:32:17

Windows 8.1CPU風扇

2023-02-27 07:36:36

渦輪風扇噪音

2018-07-12 14:56:11

機箱裝機風扇

2023-03-07 15:43:02

2017-05-28 12:15:29

2011-06-02 09:03:16

筆記本技巧
點贊
收藏

51CTO技術棧公眾號