微信小程序?qū)崿F(xiàn)身份證取景框拍攝
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)身份證取景框拍攝的具體代碼,供大家參考,具體內(nèi)容如下
wxml
<view class="camera_box">
<camera class="camera" wx:if="{{!show}}" device-position="back" flash="off" binderror="error">
<cover-view class="id_m">
<cover-image class="img" src="http://img.jbzj.com/file_images/article/202009/202099172501721.png"></cover-image>
</cover-view>
</camera>
<image class="camera_img" src="{{src}}" wx:if="{{show}}"></image>
<view class="action">
<button class="takeBtn" type="primary" bindtap="takePhoto" wx:if="{{!show}}"></button>
<button class="saveImg" type="primary" bindtap="saveImg" wx:if="{{show}}"></button>
<button class="cancelBtn" wx:if="{{show}}" type="primary" bindtap="cancelBtn"></button>
</view>
</view>
wxss
.camera_box {
height: 100vh; width: 100vw;
position: relative;
}
.camera {
height: 85vh; width: 100vw;
z-index: 1;
}
.id_m {
height: 85vh; width: 100vw;
z-index: 999;
background: rgba(0, 0, 0, 0.1);
display: flex;
position: absolute;
}
.id_m .img {
width: 550rpx;
height: 900rpx;
display: block;
position: absolute;
left: 0; right: 0; margin: auto auto;
top: 0; bottom: 0;
}
.id_m .tips_txt {
transform:rotate(90deg);
}
.camera_box .action {
height: 15vh;
position: relative;
display: flex;
justify-content: space-around;
align-items: center;
}
.camera_box .takeBtn {
height: 120rpx; width: 120rpx; border-radius: 50%;
font-size: 24rpx;
background: url('https://cdn.ctoku.com/1123123123123e3241.png') no-repeat center;
background-size: contain;
border: none;
}
.camera_box .cancelBtn {
font-size: 24rpx;
height: 120rpx; width: 120rpx; border-radius: 50%;
background: url('https://cdn.ctoku.com/12311123342312231.png') no-repeat center;
background-size: contain;
border: none;
}
.camera_box .saveImg {
background: url('https://cdn.ctoku.com/1232123434231231231.png') no-repeat center;
font-size: 24rpx;
height: 120rpx; width: 120rpx; border-radius: 50%;
background-size: contain;
border: none;
}
.camera_box .takeBtn::after {
border: none;
}
.camera_img {
height: 85vh; width: 100%;
}
js
Page({
/**
* 頁(yè)面的初始數(shù)據(jù)
*/
data: {
src: '',
show: false
},
cancelBtn () {
this.setData({show: false})
},
saveImg () {
wx.showModal({
title: '圖片地址',
content: this.data.src,
})
},
takePhoto() {
const ctx = wx.createCameraContext()
const listener = ctx.onCameraFrame((frame) => {
console.log(frame)
})
ctx.takePhoto({
quality: 'high',
success: (res) => {
console.log(res)
this.setData({
src: res.tempImagePath,
show: true
})
listener.stop({
success: (res) => {
console.log(res)
},
fail: (err) =>{
console.log(err)
}
})
},
fail: (err) => {
console.log(err)
}
})
},
error(e) {
console.log(e.detail)
},
/**
* 生命周期函數(shù)--監(jiān)聽頁(yè)面加載
*/
onLoad: function (options) {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁(yè)面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁(yè)面顯示
*/
onShow: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁(yè)面隱藏
*/
onHide: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁(yè)面卸載
*/
onUnload: function () {
},
/**
* 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動(dòng)作
*/
onPullDownRefresh: function () {
},
/**
* 頁(yè)面上拉觸底事件的處理函數(shù)
*/
onReachBottom: function () {
},
/**
* 用戶點(diǎn)擊右上角分享
*/
onShareAppMessage: function () {
}
})
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解JS如何解決大數(shù)據(jù)下滾動(dòng)頁(yè)面卡頓問(wèn)題
之前遇到不分頁(yè)直接獲取到全部數(shù)據(jù),前端滾動(dòng)查看數(shù)據(jù),頁(yè)面就挺卡頓的,所以這篇文章來(lái)和大家聊聊如何解決這一問(wèn)題,感興趣的小伙伴可以了解下2023-07-07
前端實(shí)現(xiàn)文件的斷點(diǎn)續(xù)傳(前端文件提交+后端PHP文件接收)
本文通過(guò)斷點(diǎn)續(xù)傳的簡(jiǎn)單例子(前端文件提交+后端PHP文件接收),本文以圖片為實(shí)例給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,感興趣的朋友一起看看吧2016-11-11
深入理解JavaScript系列(13) This? Yes,this!
在這篇文章里,我們將討論跟執(zhí)行上下文直接相關(guān)的更多細(xì)節(jié)。討論的主題就是this關(guān)鍵字。實(shí)踐證明,這個(gè)主題很難,在不同執(zhí)行上下文中this的確定經(jīng)常會(huì)發(fā)生問(wèn)題2012-01-01
利用JavaScript控制元素(標(biāo)簽)的顯示與隱藏
這篇文章主要給大家介紹了關(guān)于如何利用JavaScript控制元素(標(biāo)簽)的顯示與隱藏的相關(guān)資料,JavaScript有多種方式可以實(shí)現(xiàn),文中介紹了三種方法以及區(qū)別,需要的朋友可以參考下2023-07-07
JavaScript使用encodeURI()和decodeURI()獲取字符串值的方法
這篇文章主要介紹了JavaScript使用encodeURI()和decodeURI()獲取字符串值的方法,實(shí)例分析了encodeURI()和decodeURI()函數(shù)解析字符串的相關(guān)技巧,需要的朋友可以參考下2015-08-08
JS組件系列之使用HTML標(biāo)簽的data屬性初始化JS組件
這篇文章主要介紹了JS組件系列之使用HTML標(biāo)簽的data屬性初始化JS組件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
基于JS實(shí)現(xiàn)checkbox全選功能實(shí)例代碼
最近做了個(gè)項(xiàng)目其中有這樣的需求要求實(shí)現(xiàn)點(diǎn)擊全選選中所有菜單,再次點(diǎn)擊全選取消選中。下面小編給大家分享實(shí)現(xiàn)代碼,對(duì)js實(shí)現(xiàn)checkbox全選功能感興趣的朋友參考下吧2016-10-10

