成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

從微信小程序到鴻蒙js開發-swiper&animator&marquee

開發
文章由鴻蒙社區產出,想要了解更多內容請前往:51CTO和華為官方戰略合作共建的鴻蒙技術社區https://harmonyos.51cto.com/#zz

[[382656]]

想了解更多內容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術社區

https://harmonyos.51cto.com/#zz

1、swiper輪播圖

微信小程序的swiper組件中只能放置swiper-item,而鴻蒙js的swiper組件中可以放置除list之外的任意組件,功能更強大。除之前講過用swiper結合自定義tabbar實現底部菜單分頁功能,swiper最常用的就是首頁的輪播圖了。

swiper的屬性可見官方文檔(https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-components-container-swiper-0000000000611533),開發者工具在duration屬性的代碼提示是有bug的,這里應填的是毫秒數:

  1. <swiper autoplay="true" duration="1000" interval="3000" indicator="true" loop="true" vertical="false"
  2.       <block for="{{ swipeImg }}"
  3.           <image src="{{ $item }}"></image> 
  4.       </block> 
  5.   </swiper> 

代碼中swiper的后四個屬性所填的都是默認值,可以省略。

2、image-animator幻燈片

swiper是滾動輪播圖的效果,image-animator組件提供了類似幻燈片一樣的圖片切換效果。它不支持任何的子組件,且只支持圖片。官方文檔(https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-components-basic-image-animator-0000001050066126)。

image-animator的duration屬性與swiper的duration屬性不同,它支持給定單位,不給單位默認為ms。且文檔中寫的“單次播放時長”其實是一次播放完所有圖片的時長,每張圖片的顯示時長被均分。

  1. <image-animator duration="8s" images="{{ animatorImg }}"></image-animator> 

images數組格式:

  1. "animatorImg": [ 
  2.      { 
  3.          "src""newyear1.jpeg" 
  4.      }, 
  5.      { 
  6.          "src""newyear2.jpeg" 
  7.      }, 
  8.      { 
  9.          "src""newyear3.jpeg" 
  10.      }, 
  11.      { 
  12.          "src""newyear4.jpeg" 
  13.      } 
  14.  ], 

支持設置fixedsize="false",即可在數組中指定每幅圖片的長、寬、偏移量。

  1. <image-animator duration="8s" images="{{ animatorImg }}" fixedsize="false"></image-animator> 

  1. "animatorImg": [ 
  2.     { 
  3.         "src""newyear1.jpeg"
  4.         "width": 500, 
  5.         "height": 500 
  6.     }, 
  7.     { 
  8.         "src""newyear2.jpeg" 
  9.     }, 
  10.     { 
  11.         "src""newyear3.jpeg" 
  12.     }, 
  13.     { 
  14.         "src""newyear4.jpeg"
  15.         "width": 400, 
  16.         "height": 400, 
  17.         "top": 100, 
  18.         "left": 100 
  19.     } 
  20. ], 

3、marquee跑馬燈

marquee組件提供了一種跑馬燈的文字效果,文字從屏幕右側開始出現,并向屏幕左側滾動。適合做滾動通知,或是手表類的布局。

  1. <marquee> 
  2.     {{ text }} 
  3. </marquee> 

整體代碼和效果圖:

hml:

  1. <div class="container"
  2.     <swiper autoplay="true" duration="1000" interval="3000" indicator="true" loop="true" vertical="false"
  3.         <block for="{{ swipeImg }}"
  4.             <image src="{{ $item }}"></image> 
  5.         </block> 
  6.     </swiper> 
  7.     <marquee> 
  8.         {{ text }} 
  9.     </marquee> 
  10.     <image-animator duration="8s" images="{{ animatorImg }}" fixedsize="false"></image-animator> 
  11. </div> 

css:

  1. .container { 
  2.     display: flex; 
  3.     flex-direction: column
  4.     width: 100%; 
  5.     height: 1200px; 
  6. swiper { 
  7.     width: 100%; 
  8.     height: 350px; 
  9. swiper image { 
  10.     width: 100%; 
  11.     height: 350px; 
  12.  
  13. marquee { 
  14.     margin-top: 20px; 
  15.     margin-bottom: 20px; 
  16.     width: 100%; 
  17.  
  18. image-animator { 
  19.     width: 100%; 
  20.     height: 550px; 

js: (采用動靜分離,詳見下文)

  1. import fetch from '@system.fetch'
  2.  
  3. export default { 
  4.     data: { 
  5.         dataUrl: "http://milkytea.free.idcfengye.com/text/newyear.json"
  6.         swipeImg: [], 
  7.         text: ""
  8.         animatorImg: [] 
  9.     }, 
  10.     onInit() { 
  11.         fetch.fetch({ 
  12.             url: this.dataUrl, 
  13.             responseType: 'json'
  14.             success: res => { 
  15.                 let data = JSON.parse(res.data); 
  16.                 let imgUrl = data.imgUrl; 
  17.                 let swipeImg = data.swipeImg; 
  18.                 let animatorImg = data.animatorImg; 
  19.                 for (let i in swipeImg) { 
  20.                     swipeImg[i] = imgUrl + swipeImg[i]; 
  21.                 } 
  22.                 for (let i in animatorImg) { 
  23.                     animatorImg[i].src = imgUrl + animatorImg[i].src; 
  24.                 } 
  25.                 this.swipeImg = swipeImg; 
  26.                 this.text = data.text; 
  27.                 this.animatorImg = animatorImg; 
  28.             } 
  29.         }) 
  30.     } 

4、nginx動靜分離

在這個模塊中,我并沒有將圖片放在項目工程目錄中,甚至圖片的url都沒有寫在js文件中。一是現在app功能越發強大,占用的存儲空間也越來越大,如果將靜態資源全部存放在工程目錄中加大了空間的占用量。二是如果圖片定期更換,或者服務器地址更換,寫在代碼里不便于維護。

nginx服務器可以實現動靜分離,將本地路徑作為靜態資源服務器。基本配置如下,在nginx.conf中添加一個server:

  1. server{ 
  2.       listen 8500; 
  3.       server_name localhost; 
  4.  
  5.       location / { 
  6.           root /Users/liuyufeng/image/; 
  7.           autoindex on
  8.       } 
  9.  
  10.       location ~ ^/(images|text|video|audio)/ { 
  11.           root /Users/liuyufeng/image/; 
  12.           autoindex on
  13.           access_log on
  14.           expires 30d; 
  15.       } 
  16.   } 

將本地文件夾"/Users/liuyufeng/image"和localhost:8500綁定,并通過正則匹配"images","text","video","audio"四個子目錄,分別存放圖片、文本、視頻、音頻。重啟nginx后,訪問localhost:8500:

本地目錄就成為了靜態資源服務器,不得不感嘆nginx的強大。

在鴻蒙項目中,總不能請求localhost,因此再搭配內網穿透,將本地服務器和域名綁定就可以了。

剛才模塊中的js代碼,就是通過請求靜態資源中的newyear.json文件獲取圖片路徑以及文字數據,實現了動靜分離。

newyear.json

  1.     "imgUrl""http://milkytea.free.idcfengye.com/images/newyear/"
  2.     "swipeImg": ["swiper1.jpg""swiper2.jpg""swiper3.jpg"], 
  3.     "animatorImg": [ 
  4.         { 
  5.             "src""newyear1.jpeg"
  6.             "width": 500, 
  7.             "height": 500 
  8.         }, 
  9.         { 
  10.             "src""newyear2.jpeg" 
  11.         }, 
  12.         { 
  13.             "src""newyear3.jpeg" 
  14.         }, 
  15.         { 
  16.             "src""newyear4.jpeg"
  17.             "width": 400, 
  18.             "height": 400, 
  19.             "top": 100, 
  20.             "left": 100 
  21.         } 
  22.     ], 
  23.     "text""新春佳節,快樂假期,祝你放假快樂,闔家幸福,新春大吉!  福氣高,樂逍遙,生活日日美,收入月月高。" 

想了解更多內容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術社區

https://harmonyos.51cto.com/#zz

 

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

2021-02-05 09:46:16

鴻蒙HarmonyOSjs開發

2021-02-23 12:25:26

鴻蒙HarmonyOS應用開發

2021-03-02 09:29:29

鴻蒙HarmonyOS應用開發

2021-02-20 09:52:02

鴻蒙HarmonyOS應用開發

2021-02-25 10:01:19

鴻蒙HarmonyOS應用開發

2021-02-22 14:56:55

鴻蒙HarmonyOS應用開發

2021-02-23 12:23:57

鴻蒙HarmonyOS應用開發

2021-02-23 09:52:42

鴻蒙HarmonyOS應用開發

2021-02-04 13:49:41

鴻蒙HarmonyOS應用開發

2021-02-25 15:13:08

鴻蒙HarmonyOS應用開發

2021-02-07 09:17:24

鴻蒙HarmonyOS應用開發

2021-02-24 09:36:03

鴻蒙CSS應用開發

2017-05-08 15:03:07

微信小程序開發實戰

2016-09-27 16:38:24

JavaScript微信Web

2016-11-04 10:49:48

微信小程序

2016-09-28 18:10:59

微信程序MINA

2016-09-27 20:36:23

微信HttpWeb

2016-11-04 10:30:17

微信小程序

2018-09-11 10:32:07

云開發小程序開發者

2016-11-07 10:30:07

微信小程序安裝配置
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 午夜三级视频 | 成人欧美一区二区三区视频xxx | 欧美日韩1区2区3区 欧美久久一区 | 国产精品亚洲一区 | www.9191.com | 一级黄色毛片子 | 羞羞视频免费在线观看 | 成人久久 | 国产永久免费 | 97国产精品 | 蜜臀久久99精品久久久久久宅男 | 欧美黑人一级爽快片淫片高清 | 国产日韩免费视频 | 欧美精品一区二区三区四区 | 免费在线观看一区二区 | 国产精品久久久久久久一区二区 | 日韩一区二 | 福利二区 | 亚洲狠狠爱 | 婷婷综合 | 日本a视频| 免费黄色网址视频 | 亚洲+变态+欧美+另类+精品 | 国产粉嫩尤物极品99综合精品 | 一区二区在线看 | 国产精品综合一区二区 | 综合欧美亚洲 | 国产一级在线 | 久久免费国产 | 亚洲图片一区二区三区 | 成人高清视频在线观看 | 日韩av在线一区 | 日本一区二区三区四区 | 日韩欧美国产精品 | 国产精品毛片一区二区三区 | av网站免费 | 欧美激情国产日韩精品一区18 | 精品国产乱码久久久久久牛牛 | 中文字幕一区二区三区乱码在线 | 福利片在线 | 91色在线视频 |