国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

微信小程序中用WebStorm使用LESS

2019-11-19 17:14:17
字體:
供稿:網(wǎng)友

前提

自己前端不熟悉,很多都需要練習(xí)

網(wǎng)上找了一個css的demo, 放到微信小程序后,可以運行

圖片很大,沒有弄,加載可能有點慢(不相關(guān)的,就不扯了)

Less環(huán)境

Less需要nodejs的npm
nodejs的環(huán)境這里略了
自己百度

通過

npm install less -g

安裝好 less
(沒有用過的,可以理解為 maven的庫, gradle庫,pods的庫)

WebStorm的Less使用

先關(guān)聯(lián)對應(yīng)的less

當(dāng)然,對應(yīng)的wxss文件,在webstorm中的顯示,

可以參考自己其他文章

WebStorm:遇到的問題

這里,只要創(chuàng)建less文件,就會自動生成對應(yīng)的wxss文件了(當(dāng)然,寫好保存less文件,會自動刷新wxss文件,很方便吧)

直接wxss和 less的比較

我們先看下頁面

頁面很簡單

就只有一個 sky 套用 3個cloud 類

view class="container"> <view class="sky">  <view class="clouds_one"> </view >  <view class="clouds_two"> </view >  <view class="clouds_three"> </view >  <view class="clouds_three"></view> </view></view>

再看看css

.sky { height: 480px; background: #007fd5; position: relative; overflow: hidden; animation: sky_background 50s ease-out infinite;}.sky .clouds_one { background: url("../../resources/cloud/cloud_one.png"); position: absolute; left: 0; top: 0; height: 100%; width: 300%; animation: cloud 50s linear infinite; transform: translate3d(0, 0, 0);}.sky .clouds_two { background: url("../../resources/cloud/cloud_two.png"); position: absolute; left: 0; top: 0; height: 100%; width: 300%; animation: cloud 75s linear infinite; transform: translate3d(0, 0, 0);}.sky .clouds_three { background: url("../../resources/cloud/cloud_three.png"); position: absolute; left: 0; top: 0; height: 100%; width: 300%; animation: cloud 120s linear infinite; transform: translate3d(0, 0, 0);}@keyframes cloud { 0% { left: 0; } 100% { left: -200%; }}

我們發(fā)現(xiàn)有很多重復(fù)的地方

功能不難,但是占了70行,并且很難復(fù)用

修改的畫,還要看里面的邏輯

修改也不方便

Less的使用

我們簡單定義變量 和 方法以后

用less 大體是這樣的

@dodo-out-height : 480px; //@dodo-out-height : 480rpx;@dodo-bg-sky : #007fd5;@dodo-img-url-clouds_one : "../../resources/cloud/cloud_one.png";@dodo-img-url-clouds_two : "../../resources/cloud/cloud_two.png";@dodo-img-url-clouds_three : "../../resources/cloud/cloud_three.png";.sky { height: @dodo-out-height; background: @dodo-bg-sky; position: relative; overflow: hidden; animation: sky_background 50s ease-out infinite;}.sky .clouds_one { .dodo_clouds(@url:@dodo-img-url-clouds_one, @time: 50s)}.sky .clouds_two { .dodo_clouds(@url:@dodo-img-url-clouds_two, @time: 75s)}.sky .clouds_three { .dodo_clouds(@url:@dodo-img-url-clouds_three, @time: 120s)}.dodo_clouds (@url: @dodo-img-url-clouds_one, @height: 100%, @width: 300%, @time: 100s){ background: url(@url); position: absolute; left: 0; top: 0; height: 100%; width: 300%; animation: cloud @time linear infinite; transform: translate3d(0, 0, 0);}@keyframes cloud { 0% { left: 0 } 100% { left: -200% }}

保存后,

我們發(fā)現(xiàn)對應(yīng)的wxss文件,也改變了,直接生成了可以讀取的文件

和之前直接寫的文件沒有太大區(qū)別

也不會出現(xiàn)對應(yīng)的變量和方法

.sky { height: 480px; background: #007fd5; position: relative; overflow: hidden; animation: sky_background 50s ease-out infinite;}.sky .clouds_one { background: url("../../resources/cloud/cloud_one.png"); position: absolute; left: 0; top: 0; height: 100%; width: 300%; animation: cloud 50s linear infinite; transform: translate3d(0, 0, 0);}.sky .clouds_two { background: url("../../resources/cloud/cloud_two.png"); position: absolute; left: 0; top: 0; height: 100%; width: 300%; animation: cloud 75s linear infinite; transform: translate3d(0, 0, 0);}.sky .clouds_three { background: url("../../resources/cloud/cloud_three.png"); position: absolute; left: 0; top: 0; height: 100%; width: 300%; animation: cloud 120s linear infinite; transform: translate3d(0, 0, 0);}@keyframes cloud { 0% { left: 0; } 100% { left: -200%; }}

預(yù)覽下:

也沒有區(qū)別,只是代碼寫起來更方便(建議機(jī)子配置可以的畫,開發(fā)別用微信提供的ide,效率太低)

less很強(qiáng)大,其他的地方,有時間再深入,

感覺less好用在于它的復(fù)用性 :)

簡單demo源碼:http://xiazai.VeVB.COm/201703/yuanma/weapp-start-master(VeVB.COm).rar

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 松溪县| 柯坪县| 新绛县| 江源县| 海南省| 灌南县| 阜平县| 曲松县| 宜城市| 新巴尔虎左旗| 南宫市| 黄冈市| 澄城县| 宁蒗| 额济纳旗| 鸡泽县| 泗水县| 静乐县| 绥阳县| 嘉祥县| 民勤县| 扬中市| 墨玉县| 衡阳市| 花莲市| 建始县| 罗山县| 乐至县| 阜平县| 台安县| 四平市| 西华县| 沁源县| 阜宁县| 静乐县| 永州市| 芒康县| 开原市| 沙坪坝区| 来凤县| 宁强县|