首頁

微信小程序如何解析HTML富文本(使用wxParse解析富文本的demo)

seo達人

如果您想訂閱本博客內(nèi)容,每天自動發(fā)到您的郵箱中, 請點這里

1.把wxParse文件全部放入項目。

2.在wxml中import wxParse.wxml,并把template插入到到對應的位置上

[html] view plain copy
  1. <!--wxml-->  
  2. <import src="../../../wxParse/wxParse.wxml"/>  
  3. <view class="view-title">{{title}}</view>  
  4. <view class="view-time-box">  
  5.   <text class="view-date">{{date}}</text>  
  6.   <text class="view-time">{{time}}</text>  
  7. </view>  
  8. <template is="wxParse" data="{{wxParseData:article.nodes}}"/>  

3.在wxss中import wxParse.wxss,并設置樣式;比如‘wxParse-image’是富文本圖片轉(zhuǎn)化成image組件之后的類名,‘wxParse-p’是p標簽轉(zhuǎn)化成view組件后設置的類名

[css] view plain copy
  1. <!--wxss-->  
  2. @import "../../../wxParse/wxParse.wxss";  
  3. page{  
  4.   background#fff;  
  5. }  
  6. .view-title{  
  7.   line-height80rpx;  
  8.   font-size48rpx;  
  9.   color:#0C0C0C;  
  10.   overflowhidden;  
  11.   text-overflow: ellipsis;  
  12.   display: -webkit-box;  
  13.   -webkit-line-clamp: 2;  
  14.   -webkit-box-orient: vertical;  
  15.   max-height190rpx;  
  16.   min-height80rpx;  
  17.   width:690rpx;  
  18.   padding:30rpx 30rpx 0;  
  19. }  
  20. .view-time-box{  
  21.   height66rpx;  
  22.   line-height66rpx;  
  23.   font-size30rpx;  
  24.   color:#999999;  
  25.   margin-bottom40rpx;  
  26.   padding:0 30rpx;  
  27. }  
  28. .view-date{  
  29.   margin-right20rpx;  
  30. }  
  31. .wxParse-img{  
  32.   margin-top:20rpx;  
  33.   displayblock;  
  34.   position:relative;  
  35.   top:0;  
  36.   left:50%;  
  37.   transform: translateX(-50%);  
  38. }  
  39. .wxParse-p{  
  40.   text-indent2em;  
  41.   margin-top:20rpx;  
  42.   color:#0C0C0C;  
  43.   line-height:50rpx;  
  44.   font-size:34rpx;  
  45.   padding:0 30rpx 30rpx;  
  46.   text-alignjustify;  
  47. }  

4.js

[javascript] view plain copy
  1. var WxParse = require('../../../wxParse/wxParse.js');  
  2. Page({  
  3.   
  4.   /** 
  5.    * 頁面的初始數(shù)據(jù) 
  6.    */  
  7.   data: {  
  8.     title: '',  
  9.     date: "",  
  10.     time: "",  
  11.     id: ''  
  12.   },  
  13.   
  14.   /** 
  15.    * 生命周期函數(shù)--監(jiān)聽頁面加載 
  16.    */  
  17.   onLoad: function (options) {  
  18.     this.setData({  
  19.       id:options.id  
  20.     })  
  21.   },  
  22.   onShow: function () {  
  23.     wx.showLoading({  
  24.       title: '加載中...',  
  25.     })  
  26.     var that = this;  
  27.   
  28.     // 模擬獲取數(shù)據(jù)  
  29.     setTimeout(function () {  
  30.       that.setData({  
  31.         title:'僑寶柑普茶新會陳皮僑寶柑',  
  32.         date:"2018-03-01",  
  33.         time:"13:20:53"  
  34.       })  
  35.       var article = `  
  36.         <img src="../../../imgs/index/s.png"></img>  
  37.     <p>微信小程序如何解析HTML富文本(使用wxParse解析富文本的demo)微信小程序如何解析HTML富文本(使用wxParse解析富文本的demo)微信小程序如何解析HTML富文本(使用wxParse解析富文本的demo)</p>  
  38.     <p>微信小程序如何解析HTML富文本(使用wxParse解析富文本的demo)微信小程序如何解析HTML富文本(使用wxParse解析富文本的demo)微信小程序如何解析HTML富文本(使用wxParse解析富文本的demo)</p>  
  39.         <img src="../../../imgs/index/s.png"></img>  
  40.     <p>近兩年,小青柑的火爆有目共睹,嬌小玲瓏的產(chǎn)品形態(tài)、便攜式的消費場景、柑與茶結合的時尚方式以及獨特的口感和養(yǎng)生功效,都在順應著目前年輕化、多元化、便攜化的茶葉消費市場需求,讓它成為了一大爆品。</p>  
  41.       `;  
  42.       /** 
  43.       * WxParse.wxParse(bindName , type, data, target,imagePadding) 
  44.       * 1.bindName綁定的數(shù)據(jù)名(必填) 
  45.       * 2.type可以為html或者md(必填) 
  46.       * 3.data為傳入的具體數(shù)據(jù)(必填) 
  47.       * 4.target為Page對象,一般為this(必填) 
  48.       * 5.imagePadding為當圖片自適應是左右的單一padding(默認為0,可選) 
  49.       */  
  50.       WxParse.wxParse('article''html', article, that, 20);  
  51.         
  52.       // 更改數(shù)據(jù)、獲取新數(shù)據(jù)完成  
  53.       wx.hideLoading();  
  54.     }, 500)  
  55.   }  
  56. })  
具體的API可以去GitHub上查看:https://github.com/icindy/wxParse








藍藍設計www.yvirxh.cn )是一家專注而深入的界面設計公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網(wǎng)站建設 、平面設計服務


微信小程序?qū)W習參考demo源碼集合

seo達人

如果您想訂閱本博客內(nèi)容,每天自動發(fā)到您的郵箱中, 請點這里

微信小程序?qū)W習參考demo源碼集合,僅供參考學習用途?。?!

面對面翻譯 微信小程序源碼下載,語音翻譯類小程序工具http://www.henkuai.com/thread-37499-1-1.html

開源微信小程序,小團隊管理小程序下載 :http://www.henkuai.com/thread-37498-1-1.html

微信小程序多用戶商城demo,還在開發(fā)中:http://www.henkuai.com/thread-37497-1-1.html

微信小程序搶課列表demo :http://www.henkuai.com/thread-37496-1-1.html

微信小程序地圖實時顯示demo:http://www.henkuai.com/thread-37495-1-1.html

高質(zhì)量微信小程序UI組件庫:http://www.henkuai.com/thread-37492-1-1.html

購房搖號助手微信小程序下載:http://www.henkuai.com/thread-37471-1-1.html

股票金融微信小程序客戶端:http://www.henkuai.com/thread-37470-1-1.html
接龍微信小程序腳本,創(chuàng)建房間等等:http://www.henkuai.com/thread-37469-1-1.html
微信小程序統(tǒng)一中央服務器的思路,校園小情書聯(lián)盟:http://www.henkuai.com/thread-37468-1-1.html
輔導員預約微信小程序:http://www.henkuai.com/thread-37467-1-1.html
仿星巴克用心說微信小程序:http://www.henkuai.com/thread-37466-1-1.html
微信小程序頂部滑動導航菜單欄:http://www.henkuai.com/thread-37465-1-1.html
微信小程序朋友圈點贊功能,讓你的朋友圈秀起來:http://www.henkuai.com/thread-37464-1-1.html
微信小程序版 “前端TOP100”:http://www.henkuai.com/thread-37463-1-1.html
微信小程序3D輪播圖效果示例:http://www.henkuai.com/thread-37459-1-1.html
微信小程序仿滴滴打車小程序源碼下載,歡迎加入開發(fā):http://www.henkuai.com/thread-37458-1-1.html
微信小程序仿青桔單車,打開地圖掃碼開鎖:http://www.henkuai.com/thread-37436-1-1.html
微信小程序投票器,投票小程序源碼:http://www.henkuai.com/thread-37434-1-1.html
微信小程序時間軸源碼,記錄中國LGBT事件:http://www.henkuai.com/thread-37433-1-1.html
微信小程序api攔截器,完美兼容原生小程序項目:http://www.henkuai.com/thread-37431-1-1.html
微信小程序使用map組件實現(xiàn)多點定位顯示:http://www.henkuai.com/thread-37421-1-1.html
微信小程序商城前端,展示嬰幼兒商品: http://www.henkuai.com/thread-37418-1-1.html
答題小程序免費送,有人用這個“小程序”每天做100000:http://www.henkuai.com/thread-37412-1-1.html

使用微信小程序map組件開發(fā)的一個demo,各種坑:http://www.henkuai.com/thread-37400-1-1.html

微信小游戲2048源碼下載,經(jīng)典的小游戲:http://www.henkuai.com/thread-37399-1-1.html

微信小程序-菜譜百科,小程序開發(fā)學習demo :http://www.henkuai.com/thread-37380-1-1.html

鮮切水果微信小程序,水果商城小程序:http://www.henkuai.com/thread-37379-1-1.html

微信小程序線上圖書館前端+后端源碼下載,圖書查詢小程序 :http://www.henkuai.com/thread-37378-1-1.html

微信小程序日歷打卡項目下載,輕巧好用的日歷打卡組件:http://www.henkuai.com/thread-37367-1-1.html

微信小程序練手項目,包含抽屜效果、底部tab效果實現(xiàn)等:http://www.henkuai.com/thread-37365-1-1.html

【獨立小程序】志匯餐飲8.6 小程序前端修復版本:http://www.henkuai.com/thread-37344-1-1.html

仿今日頭條3.0 小程序前端 demo分享:http://www.henkuai.com/thread-37338-1-1.html

微信小程序真心話大冒險游戲,朋友聚會必備小程序:http://www.henkuai.com/thread-37337-1-1.html

微信小游戲頭腦王者自動答題輔助插件,小游戲作弊工具:http://www.henkuai.com/thread-37336-1-1.html

微信小程序左滑操作自定義組件,讓你的小程序開發(fā)更:http://www.henkuai.com/thread-37334-1-1.html

藍藍設計www.yvirxh.cn )是一家專注而深入的界面設計公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網(wǎng)站建設 、平面設計服務

【css】背景顏色漸變,文字顏色漸變,邊框顏色漸變

seo達人

如果您想訂閱本博客內(nèi)容,每天自動發(fā)到您的郵箱中, 請點這里

前言:css3的出現(xiàn)使得我們可以通過前端技術,讓網(wǎng)頁內(nèi)容變得更豐富,更華麗。今天來玩玩好玩的顏色漸變。

一、背景顏色漸變。

[html] view plain copy
  1. <body>  
  2. <style>  
  3. .content { width:300px; height:100px; line-height:100px; text-align:center; font-size:32px; font-weight:bold;  
  4. background-image:-webkit-linear-gradient(left, red 0%, blue 30%, yellow 60%, green 90%);   
  5. }  
  6. </style>  
  7. <div class="content">淺色夏沫,夏末微涼</div>  
  8. </body>  

運行效果


二、文字顏色漸變。

[html] view plain copy
  1. <body>  
  2. <style>  
  3. .content { width:300px; height:100px; line-height:100px; text-align:center; font-size:32px; font-weight:bold;  
  4. background-image:-webkit-linear-gradient(left, red 0%, blue 30%, yellow 60%, green 90%);   
  5. -webkit-background-clip:text; -webkit-text-fill-color:transparent; }  
  6. </style>  
  7. <div class="content">淺色夏沫,夏末微涼</div>  
  8. </body>  

運行效果


三、邊框顏色漸變。

[html] view plain copy
  1. <body>  
  2. <style>  
  3. .content { width:300px; height:100px; line-height:100px; text-align:center; font-size:32px; font-weight:bold;   
  4. border:10px solid;  
  5. border-image:-webkit-linear-gradient(left, red 0%, blue 30%, yellow 60%, green 90%) 10; }  
  6. </style>  
  7. <div class="content">淺色夏沫,夏末微涼</div>  
  8. </body>   

運行效果

藍藍設計www.yvirxh.cn )是一家專注而深入的界面設計公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網(wǎng)站建設 、平面設計服務


淺談jQuery之動畫

seo達人

如果您想訂閱本博客內(nèi)容,每天自動發(fā)到您的郵箱中, 請點這里

背景

jQuery提供了JS未能提供的動畫效果,利用jQuery的動畫效果,可以極大的簡化JS動畫部分的邏輯

滑入滑出動畫

  1. 滑入動畫

    定義:以下拉方式動畫效果將html內(nèi)容顯示出來

    使用方式:

    $(selector).slideDown(time,function) 
    $(selector).slideDown(2000) 
    $(selector).slideDown() 
    $(selector).slideDown(fast/normal/slow)

    time代表執(zhí)行動畫的時間,function代表動畫執(zhí)行完之后所要執(zhí)行的函數(shù)

  2. 滑出動畫

    定義:以上滑方式動畫效果將html內(nèi)容隱藏出來

    使用方式:

    $(selector).slideUp(time,function) 
    $(selector).slideUp(2000) 
    $(selector).slideUp() 
    $(selector).slideUp(fast/normal/slow)

    time代表執(zhí)行動畫的時間,function代表動畫執(zhí)行完之后所要執(zhí)行的函數(shù)

  3. 滑入滑出切換動畫

    定義:在滑入滑出動畫間切換

    使用方式:

    $(selector).slideToggle(time,function) 
    $(selector).slideToggle(2000) 
    $(selector).slideToggle() 
    $(selector).slideToggle(fast/normal/slow)

淡入淡出動畫

  1. 淡入動畫

    作用:讓元素以淡淡的進入視線的方式展現(xiàn)出來

    使用方式

    $(selector).fadeIn(time,function) 
    $(selector).fadeIn(2000) 
    $(selector).fadeIn() 
    $(selector).fadeIn(fast/normal/slow)

  2. 淡出動畫

    作用:讓元素以淡淡的離開視線的方式隱藏起來

    使用方式

    $(selector).fadeOut(time,function) 
    $(selector).fadeOut(2000) 
    $(selector).fadeOut() 
    $(selector).fadeOut(fast/normal/slow)

  3. 淡入淡出切換動畫

    作用:讓元素在淡入淡出動畫切換

    使用方式

    $(Selector).fadeToggle(time,function) 
    $(selector).fadeToggle(2000) 
    $(selector).fadeToggle() 
    $(selector).fadeToggle(fast/normal/slow)

  4. 修改opacity

    作用: 修改opacity的值

    使用方式

    $(Selector).fadeTo(time,opacity,function) 
    time可以是字符串,可以是具體數(shù)字 
    也可只有參數(shù)一、參數(shù)二

顯示隱藏動畫

  1. 顯示動畫

    作用: 將Html結構顯現(xiàn)出來

    使用方式

    $(Selector).show(time,function) 
    $(selector).show(2000) 
    $(selector).show() 
    $(selector).show(fast/normal/slow)

  2. 隱藏動畫

    作用: 將Html結構隱藏起來

    使用方式

    $(Selector).hide(time,function) 
    $(selector).hide(2000) 
    $(selector).hide() 
    $(selector).hide(fast/normal/slow)

停止動畫

  • 定義:停止正在執(zhí)行的動畫

  • 使用方式:

    $(selector).stop() 
    stop()中可以有兩個參數(shù),參數(shù)一:后續(xù)動畫是否執(zhí)行,參數(shù)二:當前動畫是否執(zhí)行完畢,默認的是(false,false),注意第一個參數(shù),true代表的是后續(xù)動畫不執(zhí)行 
    ———————————————————————————— 
    第一種:(false,false) 
    后續(xù)動畫會執(zhí)行,當前動畫不會執(zhí)行完 
    第二種:(false,true) 
    后續(xù)動畫會執(zhí)行,當前動畫會執(zhí)行完 
    第三種:(true,false) 
    后續(xù)動畫不會執(zhí)行,當前動畫不會執(zhí)行完 
    第四種:(true,true) 
    后續(xù)動畫不會執(zhí)行,當前動畫會執(zhí)行完

自定義動畫

  • 作用:執(zhí)行一組CSS屬性的自定義動畫

  • 使用方式:

    $(selector).animate({CSS定義},time,function())

藍藍設計www.yvirxh.cn )是一家專注而深入的界面設計公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網(wǎng)站建設 、平面設計服務

【css】背景顏色漸變,文字顏色漸變,邊框顏色漸變

seo達人

如果您想訂閱本博客內(nèi)容,每天自動發(fā)到您的郵箱中, 請點這里

前言:css3的出現(xiàn)使得我們可以通過前端技術,讓網(wǎng)頁內(nèi)容變得更豐富,更華麗。今天來玩玩好玩的顏色漸變。

一、背景顏色漸變。

[html] view plain copy
  1. <body>  
  2. <style>  
  3. .content { width:300px; height:100px; line-height:100px; text-align:center; font-size:32px; font-weight:bold;  
  4. background-image:-webkit-linear-gradient(left, red 0%, blue 30%, yellow 60%, green 90%);   
  5. }  
  6. </style>  
  7. <div class="content">淺色夏沫,夏末微涼</div>  
  8. </body>  

運行效果


二、文字顏色漸變。

[html] view plain copy
  1. <body>  
  2. <style>  
  3. .content { width:300px; height:100px; line-height:100px; text-align:center; font-size:32px; font-weight:bold;  
  4. background-image:-webkit-linear-gradient(left, red 0%, blue 30%, yellow 60%, green 90%);   
  5. -webkit-background-clip:text; -webkit-text-fill-color:transparent; }  
  6. </style>  
  7. <div class="content">淺色夏沫,夏末微涼</div>  
  8. </body>  

運行效果


三、邊框顏色漸變。

[html] view plain copy
  1. <body>  
  2. <style>  
  3. .content { width:300px; height:100px; line-height:100px; text-align:center; font-size:32px; font-weight:bold;   
  4. border:10px solid;  
  5. border-image:-webkit-linear-gradient(left, red 0%, blue 30%, yellow 60%, green 90%) 10; }  
  6. </style>  
  7. <div class="content">淺色夏沫,夏末微涼</div>  
  8. </body>   

運行效果

藍藍設計www.yvirxh.cn )是一家專注而深入的界面設計公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網(wǎng)站建設 、平面設計服務


Echarts x軸文本內(nèi)容太長的幾種解決方案

seo達人

如果您想訂閱本博客內(nèi)容,每天自動發(fā)到您的郵箱中, 請點這里

Echarts 標簽中文本內(nèi)容太長的時候怎么辦 ? 
- 1對文本進行傾斜 
在xAxis.axisLabe中修改rotate的值

 xAxis: {
            data: ["襯衫11111","羊毛二二","雪紡衫111","褲子111","高跟鞋11","襪子111"],//x軸中的數(shù)據(jù) name:"123",//坐標軸名稱。 nameLocation:'end',//坐標軸名稱顯示位置。 axisLabel : {//坐標軸刻度標簽的相關設置。 interval:0, rotate:"45" }
        },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

interval

坐標軸刻度標簽的顯示間隔(在類目軸中有效哦),默認會采用標簽不重疊的方式顯示標簽(也就是默認會將部分文字顯示不全) 
可以設置為0強制顯示所有標簽,如果設置為1,表示隔一個標簽顯示一個標簽,如果為3,表示隔3個標簽顯示一個標簽,以此類推

一開始我沒設置 因為標簽文本過長的原因他就自動不顯示全部 
image.png

被遮擋住就讓grid 組件離容器向上移動 把grid中的bottom的值調(diào)大一些

 grid:{//直角坐標系內(nèi)繪圖網(wǎng)格 show:true,//是否顯示直角坐標系網(wǎng)格。[ default: false ] left:"20%",//grid 組件離容器左側的距離。 right:"30px",
            borderColor:"#c45455",//網(wǎng)格的邊框顏色 bottom:"20%" // },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

image.png 
- 2.換行顯示 
在xAxis.axisLabel中 使用formatter回調(diào)函數(shù)實現(xiàn)換行

 axisLabel : {//坐標軸刻度標簽的相關設置。 formatter : function(params){ var newParamsName = "";// 最終拼接成的字符串 var paramsNameNumber = params.length;// 實際標簽的個數(shù) var provideNumber = 4;// 每行能顯示的字的個數(shù) var rowNumber = Math.ceil(paramsNameNumber / provideNumber);// 換行的話,需要顯示幾行,向上取整 /**
                             * 判斷標簽的個數(shù)是否大于規(guī)定的個數(shù), 如果大于,則進行換行處理 如果不大于,即等于或小于,就返回原標簽
                             */ // 條件等同于rowNumber>1 if (paramsNameNumber > provideNumber) { /** 循環(huán)每一行,p表示行 */ for (var p = 0; p < rowNumber; p++) { var tempStr = "";// 表示每一次截取的字符串 var start = p * provideNumber;// 開始截取的位置 var end = start + provideNumber;// 結束截取的位置 // 此處特殊處理最后一行的索引值 if (p == rowNumber - 1) { // 最后一次不換行 tempStr = params.substring(start, paramsNameNumber);
                                    } else { // 每一次拼接字符串并換行 tempStr = params.substring(start, end) + "\n";
                                    }
                                    newParamsName += tempStr;// 最終拼成的字符串 }

                            } else { // 將舊標簽的值賦給新標簽 newParamsName = params;
                            } //將最終的字符串返回 return newParamsName
                }

            }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

image.png

  • 3.文字豎直顯示 
    同樣和換行一個道理,只是這個是單個文字換行 
    在xAxis.axisLabel中 使用formatter回調(diào)函數(shù)實現(xiàn)換行
axisLabel: { interval: 0,  
                               formatter:function(value) {  
                                   return value.split("").join("\n"); } } 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

image.png

  • 4.隔一個換行 
    在xAxis.axisLabel中 使用formatter回調(diào)函數(shù)實現(xiàn)換行
axisLabel : {//坐標軸刻度標簽的相關設置。 clickable:true,//并給圖表添加單擊事件  根據(jù)返回值判斷點擊的是哪里 interval : 0,
                formatter : function(params,index){ if (index % 2 != 0) { return '\n\n' + params;
                    } else { return params;
                    }
                }

            }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

image.png

藍藍設計www.yvirxh.cn )是一家專注而深入的界面設計公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網(wǎng)站建設 、平面設計服務

怎么制作微信小程序的旋轉(zhuǎn)動畫?

seo達人

如果您想訂閱本博客內(nèi)容,每天自動發(fā)到您的郵箱中, 請點這里

微信小程序被給予的能量是無窮的,在小程序發(fā)展逐漸成熟的當下,小程序開發(fā)能實現(xiàn)的需求越來越完善。最近小程序中有一個圖片旋轉(zhuǎn)的需求,在微信小程序上是可以通過切換多張圖片達到旋轉(zhuǎn)的效果,但微信小程序自帶的API中帶有這么一個動畫組件,因此小程序制作旋轉(zhuǎn)動畫可以使用image+Animation來實現(xiàn)。

首先在wxml中定義image

注意其中的animation屬性,image就由它來實現(xiàn)動畫。

而{{animation}}我們在js的data中定義

data: {

animation: \'\'

},

相關代碼

var _animation;

var _animationIndex

const _ANIMATION_TIME = 500;

pages {

...

onShow: function () {

_animation =wx.createAnimation({

duration:_ANIMATION_TIME,

timingFunction: \'linear\',//linear,ease,ease-in,ease-in-out,ease-out,step-start,step-end

delay: 0,

transformOrigin:\'50% 50% 0\'

})

},

/**

* 實現(xiàn)image旋轉(zhuǎn)動畫,每次旋轉(zhuǎn) 120*n度

*/

rotateAni: function (n){

_animation.rotate(120* (n)).step()

this.setData({

animation:_animation.export()

})

},

/**

* 開始旋轉(zhuǎn)

*/

startAnimationInterval:function () {

var that = this;

that.rotateAni(++_loadImagePathIndex); // 進行一次旋轉(zhuǎn)

_animationIntervalId =setInterval(function () {

that.rotateAni(++_loadImagePathIndex);

},  _ANIMATION_TIME); // 沒間隔_ANIMATION_TIME進行一次旋轉(zhuǎn)

},

/**

* 停止旋轉(zhuǎn)

*/

stopAnimationInterval:function () {

if (_animationIntervalId> 0) {

clearInterval(_animationIntervalId);

_animationIntervalId= 0;

}

},

}

微信自帶的Animation可以實現(xiàn)一次動畫,然后可以通過setInterval來達到不斷旋轉(zhuǎn)的目的,在使用時,控制startAnimationInterval和stopAnimationInterval即可。


微信小程序怎么制作旋轉(zhuǎn)動畫

微信小程序視頻教程,盡在即速學院。


在使用animation時,會發(fā)現(xiàn)有時候出現(xiàn)旋轉(zhuǎn)速度很快或者反向旋轉(zhuǎn)再正向旋轉(zhuǎn)的清空,這都是由于rotate的值設置有問題。

1、rotate的值應該是上一次結束時的值,

2、如果設置了全局變量,記得在oncreate時初始化,不然第二次打開同一頁面會有問題。

注意事項:

這里為什么不直接給_animation.rotate(120 * (n)).step()設置一個足夠大的值,原因有兩點:

1、我們需要便利的控制開始和停止,

2、animation在小程序進入后臺后,會持續(xù)運行,占用手機內(nèi)存和cpu,而小程序依賴于微信,在iphone上會導致微信被終止運行

藍藍設計www.yvirxh.cn )是一家專注而深入的界面設計公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網(wǎng)站建設 、平面設計服務

css布局——flex布局

seo達人

如果您想訂閱本博客內(nèi)容,每天自動發(fā)到您的郵箱中, 請點這里、

Flex 是 Flexible Box 的縮寫,意為"彈性布局",用來為盒狀模型提供最大的靈活性。
任何一個容器都可以指定為 Flex 布局。
.box{ display: flex;}
行內(nèi)元素也可以使用 Flex 布局。
.box{ display: inline-flex;}
Webkit 內(nèi)核的瀏覽器display: -webkit-flex;
設為 Flex 布局以后,子元素的float、clearvertical-align屬性將失效。

圖片


容器屬性:

flex-direction:(排列方向橫向還是縱向)
row
(默認值):主軸為水平方向,起點在左端。
row-reverse
:主軸為水平方向,起點在右端。
column
:主軸為垂直方向,起點在上沿。
column-reverse
:主軸為垂直方向,起點在下沿。

圖片

flex-wrap:(如何換行)
nowrap
(默認):不換行。

wrap
:換行,第一行在上方。

wrap-reverse
:換行,第一行在下方。


flex-flow:(
flex-directionflex-wrap簡稱,默認值為row nowrap

justify-content:(橫向?qū)R方式)
flex-start(默認值):左對齊
flex-end
:右對齊
center
: 居中
space-between
:兩端對齊,項目之間的間隔都相等
space-around:每個項目兩側的間隔相等。所以,項目之間的間隔比項目與邊框的間隔大一倍。

圖片

align-items:(縱向?qū)R方式)
flex-start:交叉軸的起點對齊。
flex-end
:交叉軸的終點對齊。
center
:交叉軸的中點對齊。
baseline
: 項目的第一行文字的基線對齊
stretch(默認值):如果項目未設置高度或設為auto,將占滿整個容器的高度。

圖片

align-content:(多根軸線的對齊方式)
flex-start
:與交叉軸的起點對齊。
flex-end
:與交叉軸的終點對齊。
center
:與交叉軸的中點對齊。
space-between
:與交叉軸兩端對齊,軸線之間的間隔平均分布。
space-around
:每根軸線兩側的間隔都相等。所以,軸線之間的間隔比軸線與邊框的間隔大一倍
stretch(默認值):軸線占滿整個交叉軸。

圖片

 
box屬性:


order:(排列順序)
數(shù)值越小,排列越靠前,默認為0。

flex-grow:(剩余空間分配,box放大比例,默認為0,即如果存在剩余空間,也不放大)

圖片

flex-shrink:(box縮小比例,默認為1,即如果空間不足,該項目將縮?。?br style="box-sizing:border-box;outline:0px;word-break:break-all;" />
圖片

flex-basis:(box占據(jù)的寬度或高度)

圖片

align-self:(單個box的對齊方式,與其他box對齊方式)

圖片
藍藍設計www.yvirxh.cn )是一家專注而深入的界面設計公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網(wǎng)站建設 、平面設計服務

使用three.js的著色器通道渲染地球模型

seo達人

如果您想訂閱本博客內(nèi)容,每天自動發(fā)到您的郵箱中, 請點這里

我們都知道,three.js庫里面內(nèi)置了很多著色器通道對象供我們渲染場景,本文將對EffectComposer、RenderPass、FilmPass這三個通道進行學習和實現(xiàn):

1.RenderPass這個通道會在當前場景(scene)和攝像機(camera)的基礎上渲染出一個新場景,新建:

[javascript] view plain copy
  1. let renderPass = new THREE.RenderPass(scene, camera);  

2.FilmPass這個通道通過掃描線和失真模擬電視屏幕效果,實現(xiàn)的效果超有時代感,新建:

[javascript] view plain copy
  1. /*四個參數(shù)分別為粗糙程度,掃描線強度,掃描線數(shù)量,是否轉(zhuǎn)換為灰度圖*/  
  2. let effectFilm = new THREE.FilmPass(0.8, 0.325, 256, false);  
  3. //將渲染結果輸出到屏幕  
  4. effectFilm.renderToScreen = true;  

3.EffectComposer可以理解為著色器通道容器,著色器通道按照先后順序添加進來并執(zhí)行,新建:

[javascript] view plain copy
  1. /*渲染效果組合器,每個通道都按照傳入的順序執(zhí)行*/  
  2. let composer = new THREE.EffectComposer(renderer);  
  3. composer.addPass(renderPass);  
  4. composer.addPass(effectFilm);  

本文實現(xiàn)的demo基于three.js_r86(請自行下載),代碼所用js文件和圖片都在下載的那個包里面,請讀者自行引用。

實現(xiàn)效果:



代碼:

[html] view plain copy
  1. <!DOCTYPE html>  
  2. <html lang="en">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>shader_2_earth</title>  
  6.     <style>  
  7.         body{  
  8.             margin: 0;  
  9.             overflow: hidden;  
  10.         }  
  11.     </style>  
  12. </head>  
  13. <body>  
  14. <script src="build/three.js"></script>  
  15. <script src="js/libs/stats.min.js"></script>  
  16. <script src="js/libs/dat.gui.min.js"></script>  
  17. <script src="js/controls/OrbitControls.js"></script>  
  18. <script src="js/Detector.js"></script>  
  19.   
  20. <script src="js/postprocessing/EffectComposer.js"></script>  
  21. <script src="js/postprocessing/ShaderPass.js"></script>  
  22. <script src="js/postprocessing/MaskPass.js"></script>  
  23. <script src="js/postprocessing/FilmPass.js"></script>  
  24. <script src="js/postprocessing/BloomPass.js"></script>  
  25. <script src="js/postprocessing/RenderPass.js"></script>  
  26.   
  27. <script src="js/shaders/CopyShader.js"></script>  
  28. <script src="js/shaders/FilmShader.js"></script>  
  29.   
  30. <div id="stats"></div>  
  31. <div id="container"></div>  
  32. <script>  
  33.     //檢測webgl的兼容性  
  34.    if(!Detector.webgl) Detector.addGetWebGLMessage();  
  35.   
  36.    let scene;  
  37.    let camera, renderer, sphere, controls, stats;  
  38.    let ambientLight, spotLight;  
  39.    let composer;  
  40.    let clock;  
  41.   
  42.    main();  
  43.    render();  
  44.   
  45.    function main() {  
  46.        scene = new THREE.Scene();  
  47.   
  48.        camera = new THREE.PerspectiveCamera(45, window.innerWidth/window.innerHeight, 0.1, 1000);  
  49.        camera.position.set(-10, 15, 25);  
  50.        camera.lookAt(new THREE.Vector3(0, 0, 0));  
  51.   
  52.        renderer = new THREE.WebGLRenderer({antialias:true});  
  53.        renderer.setClearColor(new THREE.Color(0,0,0));  
  54.        renderer.setSize(window.innerWidth, window.innerHeight);  
  55.        renderer.shadowMapEnabled = true;  
  56.   
  57.        controls = new THREE.OrbitControls(camera);  
  58.        controls.autoRotate = false;  
  59.   
  60.        clock = new THREE.Clock();  
  61.   
  62.        ambientLight = new THREE.AmbientLight(0x181818);  
  63.        scene.add(ambientLight);  
  64.   
  65.        spotLight = new THREE.SpotLight(0xffffff);  
  66.        spotLight.position.set(550, 100, 550);  
  67.        spotLight.intensity = 0.6;  
  68.        scene.add(spotLight);  
  69.   
  70.        //創(chuàng)建地球  
  71.        sphere = createMesh(new THREE.SphereGeometry(10, 60, 60));  
  72.        scene.add(sphere);  
  73.   
  74.        document.getElementById("container").appendChild(renderer.domElement);  
  75.   
  76.        /**  
  77.         * 添加渲染通道  
  78.         */  
  79.        //在當前場景和攝像機的基礎上渲染一個新場景  
  80.        let renderPass = new THREE.RenderPass(scene, camera);  
  81.        //通過掃描線和失真來實現(xiàn)模擬電視屏幕的效果  
  82.        let effectFilm = new THREE.FilmPass(0.8, 0.325, 256, false);  
  83.        //將渲染結果輸出到屏幕  
  84.        effectFilm.renderToScreen = true;  
  85.   
  86.        //渲染效果組合器,每個通道都按照傳入的順序執(zhí)行  
  87.        composer = new THREE.EffectComposer(renderer);  
  88.        composer.addPass(renderPass);  
  89.        composer.addPass(effectFilm);  
  90.   
  91.        //菜單欄元素  
  92.        let guiFields = {  
  93.            "掃描線數(shù)量": 256,  
  94.            "灰度圖像": false,  
  95.            "掃描線強度": 0.3,  
  96.            "粗糙程度": 0.8,  
  97.            "updateEffectFilm": function () {  
  98.                effectFilm.uniforms.grayscale.value = guiFields.灰度圖像;  
  99.                effectFilm.uniforms.nIntensity.value = guiFields.粗糙程度;  
  100.                effectFilm.uniforms.sIntensity.value = guiFields.掃描線強度;  
  101.                effectFilm.uniforms.sCount.value = guiFields.掃描線數(shù)量;  
  102.            }  
  103.        };  
  104.   
  105.        //新建一個菜單欄  
  106.        let gui = new dat.GUI();  
  107.        gui.add(guiFields, "掃描線數(shù)量", 0, 2048).onChange(guiFields.updateEffectFilm);  
  108.        gui.add(guiFields, "掃描線強度", 0, 1).onChange(guiFields.updateEffectFilm);  
  109.        gui.add(guiFields, "粗糙程度", 0, 3).onChange(guiFields.updateEffectFilm);  
  110.        gui.add(guiFields, "灰度圖像").onChange(guiFields.updateEffectFilm);  
  111.   
  112.        stats = initStats();  
  113.    }  
  114.   
  115.    //創(chuàng)建一個Mesh  
  116.    function createMesh(geometry) {  
  117.   
  118.        //初始化紋理加載器  
  119.        let textureLoader = new THREE.TextureLoader();  
  120.        //加載圖片  
  121.        let uniforms = {  
  122.            planetTexture:{value:textureLoader.load("textures/planets/earth_atmos_2048.jpg")},  
  123.            specularTexture:{value:textureLoader.load("textures/planets/earth_specular_2048.jpg")},  
  124.            normalTexture:{value:textureLoader.load("textures/planets/earth_normal_2048.jpg")}  
  125.        };  
  126.   
  127.        //創(chuàng)建phong材料,并進行相應圖片的貼圖  
  128.        let planetMaterial = new THREE.MeshPhongMaterial();  
  129.        planetMaterial.specularMap = uniforms.specularTexture.value;  
  130.        planetMaterial.specular = new THREE.Color(0x4444aa);  
  131.   
  132.        planetMaterial.normalMap = uniforms.normalTexture.value;  
  133.        planetMaterial.map = uniforms.planetTexture.value;  
  134.   
  135.        //新建一個mesh  
  136.        let mesh = new THREE.SceneUtils.createMultiMaterialObject(geometry, [planetMaterial]);  
  137.   
  138.        return mesh;  
  139.    }  
  140.   
  141.    //渲染更新場景  
  142.   
  143.    function render() {  
  144.        stats.update();  
  145.        let delta = clock.getDelta();  
  146.        controls.update(delta);  
  147.        sphere.rotation.y += 0.002;  
  148.        requestAnimationFrame(render);  
  149.   
  150.        //沒有著色器通道系統(tǒng)默認為WebGLRenderer.render  
  151.        //使用著色器通道后,應使用使用composer.render  
  152.        composer.render(delta);  
  153.    }  
  154.   
  155.    //左上角幀顯示  
  156.    function initStats() {  
  157.        let stats = new Stats();  
  158.        stats.setMode(0);  
  159.        stats.domElement.style.position = 'absolute';  
  160.        stats.domElement.style.left = '0px';  
  161.        stats.domElement.style.top = '0px';  
  162.        document.getElementById("stats").appendChild(stats.domElement);  
  163.   
  164.        return stats;  
  165.    }  
  166. </script>  
  167. </body>  
  168. </html>  
藍藍設計www.yvirxh.cn )是一家專注而深入的界面設計公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網(wǎng)站建設 平面設計服務

include指令標記與動作標記詳解

seo達人

如果您想訂閱本博客內(nèi)容,每天自動發(fā)到您的郵箱中, 請點這里

一.include指令標記

include指令標記用于把JSP文件,HTML網(wǎng)文文件等文件靜態(tài)嵌入當前JSP網(wǎng)頁中,語法如下:

[html] view plain copy
  1. <%@include file="xxURL"%>  

靜態(tài)嵌入就是“先包含后處理”在編譯階段完成對文件嵌入,即先將當前JSP頁面與被嵌入文件合并成一個新的JSP頁面

eg:

[html] view plain copy
  1. <%@ page language="java" contentType="text/html; charset=utf-8"  
  2.     pageEncoding="ISO-8859-1"%>  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  4. <html>  
  5. <head>  
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  7. <title>Insert title here</title>  
  8. </head>  
  9. <body>  
  10.         <font color="red"size=5>  
  11.             lalla  
  12.         </font>  
  13. </body>  
  14. </html>  
            
[html] view plain copy
  1. <%@ page language="java" contentType="text/html; charset=utf-8"  
  2.     pageEncoding="UTF-8"%>  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  4. <html>  
  5. <head>  
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  7. <title>include動作標記</title>  
  8. </head>  
  9. <body>  
  10.     <br>  
  11.         <jsp:include page="demo.jsp"/>  
  12.     </br>  
  13. </body>  
  14. </html>  
運行結果如下:


二.include動作標記:

動作標記是將JSP等文件動態(tài)嵌入當前JSP網(wǎng)頁中,語法如下:
[html] view plain copy
  1. <jsp:include page="xxURL"/>  

[html] view plain copy
  1. <jsp:include page="xxURL">  
  2.    子標記  
  3. <jsp:include/>  

動態(tài)嵌入就是“先處理后包含”在運行階段完成對文件嵌入,即在把JSP頁面轉(zhuǎn)譯為JAVA文件時,并不合并兩個頁面。

eg:

[html] view plain copy
  1. <%@ page language="java" contentType="text/html; charset=utf-8"  
  2.     pageEncoding="ISO-8859-1"%>  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  4. <html>  
  5. <head>  
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  7. <title>Insert title here</title>  
  8. </head>  
  9. <body>  
  10.         <font color="red"size=5>  
  11.             lalla  
  12.         </font>  
  13. </body>  
  14. </html>  

[html] view plain copy
  1. <%@ page language="java" contentType="text/html; charset=utf-8"  
  2.     pageEncoding="UTF-8"%>  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  4. <html>  
  5. <head>  
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  7. <title>include動作標記</title>  
  8. </head>  
  9. <body>  
  10.     <br>  
  11.         <jsp:include page="demo.jsp"/>  
  12.     </br>  
  13. </body>  
  14. </html>  

運行結果:

總結:靜態(tài)嵌入中嵌入頁面與原頁面合并了,動態(tài)嵌入則還沒有。

動態(tài)嵌入與靜態(tài)嵌入相比較,動態(tài)嵌入執(zhí)行速度稍慢,但是靈活性較高。

藍藍設計www.yvirxh.cn )是一家專注而深入的界面設計公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網(wǎng)站建設 、平面設計服務


日歷

鏈接

個人資料

藍藍設計的小編 http://www.yvirxh.cn

存檔