這篇文章將為大家詳細講解有關微信小程序中如何利用WebStorm使用LESS,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
我們一直強調成都網站制作、成都做網站、外貿營銷網站建設對于企業的重要性,如果您也覺得重要,那么就需要我們慎重對待,選擇一個安全靠譜的網站建設公司,企業網站我們建議是要么不做,要么就做好,讓網站能真正成為企業發展過程中的有力推手。專業網絡公司不一定是大公司,創新互聯公司作為專業的網絡公司選擇我們就是放心。
Less環境
Less需要nodejs的npm
nodejs的環境這里略了
自己百度通過
npm install less -g
安裝好 less
WebStorm的Less使用
先關聯對應的less
當然,對應的wxss文件,在webstorm中的顯示,
可以參考自己其他文章
WebStorm:遇到的問題
這里,只要創建less文件,就會自動生成對應的wxss文件了(當然,寫好保存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%; } }
我們發現有很多重復的地方
功能不難,但是占了70行,并且很難復用
修改的畫,還要看里面的邏輯
修改也不方便
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% } }
保存后,
我們發現對應的wxss文件,也改變了,直接生成了可以讀取的文件
和之前直接寫的文件沒有太大區別
也不會出現對應的變量和方法
.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%; } }
預覽下:
也沒有區別,只是代碼寫起來更方便(建議機子配置可以的畫,開發別用微信提供的ide,效率太低)
less很強大,其他的地方,有時間再深入,
感覺less好用在于它的復用性 :)
關于“微信小程序中如何利用WebStorm使用LESS”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
文章標題:微信小程序中如何利用WebStorm使用LESS
網頁URL:http://vcdvsql.cn/article28/pejdjp.html
成都網站建設公司_創新互聯,為您提供App設計、做網站、建站公司、軟件開發、ChatGPT、網站制作
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯