微信小程序自定義掃碼功能界面的實(shí)現(xiàn)代碼
小程序的一個(gè)掃碼頁面,掃碼界面一直開著,同時(shí)可以處理其他功能,如下:
由于直接調(diào)用微信的scanCode,無法自定義界面,所以只能使用原生組件camera,完成這個(gè)功能,關(guān)于掃描框的四個(gè)角的圖片,就自己畫一下吧,中間的移動(dòng)橫線,使用了小程序的動(dòng)畫功能,在原生camera組件上,覆蓋需要用到cover-view和cover-image,同時(shí)加入了提示音
/**scan.wxss**/ .scan-view { width: 100%; height: 100%; display: flex; flex-direction: column; background-color: #B9BEC4; position: fixed; align-items: center; justify-content: space-around; } .scan-border { width: 94%; height: 94%; border: 6rpx solid #08FDFE; border-radius: 10rpx; display: flex; flex-direction: column; align-items: center; } .scan-camera { width: 500rpx; height: 500rpx; border-radius: 6rpx; margin: 30rpx; } .cover-corner { width: 80rpx; height: 80rpx; position: absolute; } .cover-left-top { left: 0; top: 0; } .cover-right-top { right: 0; top: 0; } .cover-left-bottom { left: 0; bottom: 0; } .cover-right-bottom { right: 0; bottom: 0; } .scan-animation { position: absolute; top: -10rpx; left: 10rpx; width: 480rpx; height: 8rpx; background-color: #08FDFE; border-radius: 50%; }
<!--scan.wxml--> <view class="scan-view"> <view class='scan-border'> <camera class='scan-camera' mode="scanCode" binderror="cameraError" bindscancode='scancode' frame-size='large'> <cover-image class='cover-corner cover-left-top' src='/images/left-top.png'></cover-image> <cover-image class='cover-corner cover-right-top' src='/images/right-top.png'></cover-image> <cover-image class='cover-corner cover-left-bottom' src='/images/left-bottom.png'></cover-image> <cover-image class='cover-corner cover-right-bottom' src='/images/right-bottom.png'></cover-image> <cover-view class='scan-animation' animation="{{animation}}"></cover-view> </camera> <!-- 這里可以處理其他內(nèi)容 --> </view> </view>
// scan.js // 移動(dòng)動(dòng)畫 let animation = wx.createAnimation({}); // 提示音 let innerAudioContext = wx.createInnerAudioContext() innerAudioContext.src = '/images/beep.mp3' Page({ data: { }, onLoad: function () { }, onShow(){ this.donghua() }, donghua(){ var that = this; // 控制向上還是向下移動(dòng) let m = true setInterval(function () { if (m) { animation.translateY(250).step({ duration: 3000 }) m = !m; } else { animation.translateY(-10).step({ duration: 3000 }) m = !m; } that.setData({ animation: animation.export() }) }.bind(this), 3000) }, scancode(e){ // 提示音 innerAudioContext.play() // 校驗(yàn)掃描結(jié)果,并處理 let res = e.detail.result } })
總結(jié)
到此這篇關(guān)于微信小程序自定義掃碼功能界面的實(shí)現(xiàn)代碼的文章就介紹到這了,更多相關(guān)微信小程序自定義掃碼內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JavaScript數(shù)據(jù)結(jié)構(gòu)Number
這篇文章主要介紹了JavaScript數(shù)據(jù)結(jié)構(gòu)Number,Number?是JavaScript的基本數(shù)據(jù)結(jié)構(gòu),是對(duì)應(yīng)數(shù)值的應(yīng)用類型,下文給大家分享JavaScript使用?Number?的常見問題,需要的朋友可以參考一下2022-02-02通用javascript代碼判斷版本號(hào)是否在版本范圍之間
通用判斷版本號(hào)是否在兩者之間,也可以搭配判斷是否大于某版本號(hào),小于取反即可,本文給大家介紹通用javascript代碼判斷版本號(hào)是否在版本范圍之間,需要的朋友參考下2015-11-11JS中實(shí)現(xiàn)replaceAll的方法(實(shí)例代碼)
本文是對(duì)JS中實(shí)現(xiàn)replaceAll的方法進(jìn)行了詳細(xì)的總結(jié)介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2013-11-11一個(gè)JavaScript繼承的實(shí)現(xiàn)
一個(gè)JavaScript繼承的實(shí)現(xiàn)...2006-10-10JavaScript類型系統(tǒng)之正則表達(dá)式
正則又叫規(guī)則或模式,是一個(gè)強(qiáng)大的字符串匹配工具。javascript通過RegExp類型來支持正則表達(dá)式,本文給大家介紹javascript類型系統(tǒng)之正則表達(dá)式,對(duì)js正則表達(dá)式相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2016-01-01JS實(shí)現(xiàn)單擊輸入框彈出選擇框效果完整實(shí)例
這篇文章主要介紹了JS實(shí)現(xiàn)單擊輸入框彈出選擇框效果的方法,涉及JavaScript響應(yīng)鼠標(biāo)事件動(dòng)態(tài)操作頁面元素與相關(guān)屬性的實(shí)現(xiàn)技巧,需要的朋友可以參考下2015-12-12基于javascript實(shí)現(xiàn)圖片切換效果
這篇文章主要介紹了基于javascript實(shí)現(xiàn)圖片切換效果的相關(guān)資料,需要的朋友可以參考下2016-04-04KnockoutJS 3.X API 第四章之?dāng)?shù)據(jù)控制流component綁定
這篇文章主要介紹了KnockoutJS 3.X API 第四章之?dāng)?shù)據(jù)控制流component綁定的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10