時(shí)間:2023-04-23 16:42:02 | 來源:網(wǎng)站運(yùn)營
時(shí)間:2023-04-23 16:42:02 來源:網(wǎng)站運(yùn)營
小程序?qū)崙?zhàn)--仿bilibil(嗶哩嗶哩)小程序:摘要: 之前就被朋友安利使用小程序,最近接近了小程序,發(fā)現(xiàn)了它竟然帶來了一場(chǎng)“大革命”。 簡(jiǎn)單說,它就是一個(gè)可以實(shí)現(xiàn)之前只能是原生態(tài)APP可以實(shí)現(xiàn)的效果和功能。比如說,一些酷炫的頁面與轉(zhuǎn)場(chǎng),一些可以直接和手機(jī)硬件交互的功能,錄音啊,拍視頻啊,調(diào)用手機(jī)的重力感應(yīng)啊,GPS啊等等。├── app.js├── app.json├── app.wxss├── utils│ └── util.js├── pages│ ├── common│ │ ├── header.wxml│ │ └── item.wxml│ ├── index│ │ ├── index.js│ │ ├── index.wxml│ │ └── index.wxss│ ├── selectColor│ │ ├── selectColor.js│ │ ├── selectColor.wxml│ │ └── selectColor.wxss│ ├── play│ │ ├── play.js│ │ ├── play.json│ │ ├── play.wxml│ │ └── play.wxss└── resources └── images
"pages":[ "pages/index/index", "pages/play/play", "pages/selectColor/selectColor" ],
<scroll-view class="scroll-view_H" scroll-x="true" style="width: 100%"> <text wx:for="{{section}}" wx:key="id" id="{{item.id}}" catchtap="handleTap" class="nav-name {{item.id == currentId ? 'nav-hover' : ''}}" style=" padding-right:{{topdistance}}px;padding-left:{{topdistance}}px">{{item.name}}</text> </scroll-view> </view> </view> <block wx:if="{{currentId == 1001}}"> <view class="slider-wrapper"> <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" indicator-active-color="#EA6CAF"> <block wx:for="{{imgUrls}}"> <swiper-item> <navigator url="{{item.link}}" hover-class="navigator-hover"> <image src="{{item.url}}" class="slide-image" width="355" height="150" /> </navigator> </swiper-item> </block> </swiper> </view>onLoad: function (options) { // 頁面初始化 options為頁面跳轉(zhuǎn)所帶來的參數(shù) this.setTopDistance(); this.setData({ stagePoint: util.stagePoint() }) if (this.data.currentId == 1001) { this.Page(); } else if (this.data.currentId == 1004) { this.channelPage(); } else if (this.data.currentId == 1003) { this.livePage(); } }
頂部導(dǎo)航欄實(shí)際就是利用scroll-view控件,給他綁定當(dāng)前頁面的id,當(dāng)觸發(fā)點(diǎn)擊事件時(shí),加載與該id匹配的信息。要注意的是一開始要給currentId一個(gè)頁面的值,不然無法顯示出來。Page({ inputValue: '', data: { isRandomColor: true, src: '', numberColor: "#ff0000", danmuList: [{ text: '這波不虧呀', color: '#ff0000', time: 1 }, { text: '大神666', color: '#00ff00', time: 2 }, { text: '今生無悔入fate', color: '#D9D919', time: 3 }, { text: '吾王賽高(?ò ? ó?)', color: '#C0D9D9', time: 4 } ], showModalStatus: false }, powerDrawer: function (e) { var currentStatu = e.currentTarget.dataset.statu; this.util(currentStatu) }, util: function (currentStatu) { /* 動(dòng)畫部分 */ // 第1步:創(chuàng)建動(dòng)畫實(shí)例 var animation = wx.createAnimation({ duration: 200, //動(dòng)畫時(shí)長 timingFunction: "linear", //線性 delay: 0 //0則不延遲 }); // 第2步:這個(gè)動(dòng)畫實(shí)例賦給當(dāng)前的動(dòng)畫實(shí)例 this.animation = animation; // 第3步:執(zhí)行第一組動(dòng)畫:Y軸偏移240px后(盒子高度是240px),停 animation.translateY(240).step(); // 第4步:導(dǎo)出動(dòng)畫對(duì)象賦給數(shù)據(jù)對(duì)象儲(chǔ)存 this.setData({ animationData: animation.export() }) // 第5步:設(shè)置定時(shí)器到指定時(shí)候后,執(zhí)行第二組動(dòng)畫 setTimeout(function () { // 執(zhí)行第二組動(dòng)畫:Y軸不偏移,停 animation.translateY(0).step() // 給數(shù)據(jù)對(duì)象儲(chǔ)存的第一組動(dòng)畫,更替為執(zhí)行完第二組動(dòng)畫的動(dòng)畫對(duì)象 this.setData({ animationData: animation }) //關(guān)閉抽屜 if (currentStatu == "close") { wx.createVideoContext('myVideo').play(); this.setData( { showModalStatus: false, } ); } }.bind(this), 200) // 顯示抽屜 if (currentStatu == "open") { wx.createVideoContext('myVideo').pause(); this.setData( { showModalStatus: true } ); } }, onLoad: function onLoad() { var _this = this; wx.getSystemInfo({ success: function success(res) { // video標(biāo)簽?zāi)J(rèn)寬度300px、高度225px var windowWidth = res.windowWidth; var videoHeight = 225 / 300 * windowWidth; _this.setData({ videoWidth: windowWidth, videoHeight: videoHeight }); } }); }, onReady: function onReady(res) { this.videoContext = wx.createVideoContext('myVideo'); }, onShow: function onShow() { var _this = this; wx.getStorage({ key: 'numberColor', success: function success(res) { _this.setData({ numberColor: res.data }); } }); }, bindInputBlur: function (e) { this.inputValue = e.detail.value; } }})
參考了開源代碼后,發(fā)現(xiàn)彈幕其實(shí)就是對(duì)字進(jìn)行動(dòng)畫效果,沿著y軸滾動(dòng)出現(xiàn),利用計(jì)時(shí)器不停播放多組動(dòng)畫,抽屜效果也就是對(duì)遮罩層的利用,然后利用動(dòng)畫效果,將彈出欄顯示出來,在制作時(shí),記得讓視頻暫停,這樣才能給用戶一個(gè)好的體驗(yàn),畢竟沒有人想錯(cuò)過一部精彩的視頻( ̄y▽ ̄)~onShareAppMessage: function onShareAppMessage() { wx.createVideoContext('myVideo').pause(); return { title: '【Fate全系列】英靈亂斗: 奪回未來的戰(zhàn)爭(zhēng)「Grand Order」', desc: '【Fate全系列】英靈亂斗: 奪回未來的戰(zhàn)爭(zhēng)「Grand Order」', path: '/pages/play/play', success: function (res) { // 轉(zhuǎn)發(fā)成功 wx.showToast({ title: '成功', icon: 'succes', duration: 1000, mask: true }) wx.createVideoContext('myVideo').play(); }, fail: function (res) { // 轉(zhuǎn)發(fā)失敗 wx.showToast({ title: '失敗', icon: 'fail', duration: 1000, mask: true }) wx.createVideoContext('myVideo').play(); } } }
這是我的寫法,下面給出api內(nèi)容,可以根據(jù)不同人的想法進(jìn)行修改。onShareAppMessage: function () { return { title: '自定義分享標(biāo)題', path: '/page/user?id=123' } }
但是這個(gè)id很多人不明白是什么id,之前我也不明白,后來發(fā)現(xiàn)這個(gè)id就是你要分享的這篇文章的id,但是一定要注意異步與同步的問題。關(guān)鍵詞:程序,實(shí)戰(zhàn)
客戶&案例
營銷資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。