国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 網(wǎng)站 > WEB開發(fā) > 正文

基于MUI框架的HTML5+的二維碼掃描實(shí)現(xiàn)

2024-04-27 15:16:23
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
Barcode的一個(gè)實(shí)現(xiàn)案例一、簡(jiǎn)介        Barcode模塊管理?xiàng)l碼掃描,提供常見的條碼(二維碼及一維碼)的掃描識(shí)別功能,可調(diào)用設(shè)備的攝像頭對(duì)條碼圖片掃描進(jìn)行數(shù)據(jù)輸入。通過(guò)plus.barcode可獲取條碼碼管理對(duì)象。二、實(shí)現(xiàn)的效果實(shí)現(xiàn)效果圖三、實(shí)現(xiàn) 代碼
<!doctype html><html>   <head>	<meta charset="UTF-8">	<title></title>	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />	<link href="CSS/mui.min.css" rel="stylesheet" />	<script src="js/mui.min.js"></script>	<style type="text/css">		#bcid{			width: 100%;			height: 100%;			position: absolute;			background: #000000;		}		html, body ,div{			height:100%;			width: 100%;		}		.fbt{			color: #0E76E1;			width: 50%;			background-color: #ffffff;			float: left; 			line-height: 44px;			text-align: center;		}	</style>   </head>  <body>	<header class="mui-bar mui-bar-nav" style="background-color: #ffffff;">	  <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>	  <h1 class="mui-title" style="color: #0E76E1;">物品二維碼掃描</h1>	  <span class="mui-icon mui-icon-spinner-cycle mui-spin mui-pull-right" id="turnTheLight"></span>	</header>			<div id="bcid">   	     <!--盛放掃描控件的div-->  			</div>			<div class="mui-bar mui-bar-footer" style="padding: 0px;">		<div class="fbt" onclick="scanPicture();">從相冊(cè)選擇二維碼</div>		<div class="fbt mui-action-back">取  消</div>	</div>			<script type="text/javascript">	       scan = null;//掃描對(duì)象		mui.plusReady(function () {	          mui.init();		  startRecognize();	       });					function startRecognize(){		   try{			  var filter;			 //自定義的掃描控件樣式			 var styles = {frameColor: "#29E52C",scanbarColor: "#29E52C",background: ""}			//掃描控件構(gòu)造			scan = new plus.barcode.Barcode('bcid',filter,styles);			scan.onmarked = onmarked; 			scan.onerror = onerror;			scan.start();			//打開關(guān)閉閃光燈處理			var flag = false;			document.getElementById("turnTheLight").addEventListener('tap',function(){			   if(flag == false){			      scan.setFlash(true);			      flag = true;			   }else{			     scan.setFlash(false);			     flag = false;			   }			});		  }catch(e){			alert("出現(xiàn)錯(cuò)誤啦:/n"+e);		     }		  };			function onerror(e){					alert(e);			};			function onmarked( type, result ) {					var text = '';					switch(type){						case plus.barcode.QR:						text = 'QR: ';						break;						case plus.barcode.EAN13:						text = 'EAN13: ';						break;						case plus.barcode.EAN8:						text = 'EAN8: ';						break;					}					alert( text + " : "+ result );								};				    		// 從相冊(cè)中選擇二維碼圖片 		function scanPicture() {		    plus.gallery.pick(function(path){			    plus.barcode.scan(path,onmarked,function(error){					plus.nativeUI.alert( "無(wú)法識(shí)別此圖片" );				});		    },function(err){		        plus.nativeUI.alert("Failed: "+err.message);		    });		}	    			    		</script>	</body></html>三、做的過(guò)程中遇見的問(wèn)題   a,div占滿整個(gè)頁(yè)面       1,此div寬高都為100%,父級(jí)元素的高度也為此(依次類推直至根節(jié)點(diǎn)),或者此div的position為absolute;       2,可采用js動(dòng)態(tài)設(shè)置頁(yè)面寬高
var height = window.innerHeight + 'px';//獲取頁(yè)面實(shí)際高度var width = window.innerWidth + 'px';document.getElementById("bcid").style.height= height;document.getElementById("bcid").style.width= width;        b,掃描控件有上下邊距采用填充黑色來(lái)淡化視覺(jué)上面的差異,未實(shí)際解決,(如果你解決的話,歡迎留言,謝謝)
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 斗六市| 赤壁市| 武山县| 平利县| 晋州市| 天峻县| 剑阁县| 通化县| 朝阳区| 青州市| 托克逊县| 南澳县| 金阳县| 区。| 乐平市| 金溪县| 虞城县| 郁南县| 闽侯县| 洛浦县| 临邑县| 辽宁省| 沂水县| 太原市| 阳新县| 陆良县| 高雄市| 定边县| 清远市| 太康县| 洛南县| 巨野县| 隆化县| 河北省| 乃东县| 牡丹江市| 荔波县| 海丰县| 鄯善县| 邮箱| 潮州市|