uni-app實現(xiàn)全局水印示例詳解
使用方法
1、在App.vue中引入并設置水印
2、本例子使用的水印圖片是250*250px的,可以根據(jù)需要自己調(diào)整樣式
3、watermark.js內(nèi)容見下方
<script> import watermark from '@/commons/framework/watermark.js' export default { onLaunch: function() { watermark.set('/static/framework/imgs/watermark.png'); }, onShow: function() { console.log('App Show'); }, onHide: function() { console.log('App Hide') } } </script>
watermark.js
'use strict'; let watermark = {}; watermark.set = (path) => { let id = '1.23452384164.123412415'; // #ifdef H5 if (document.getElementById(id) !== null) { document.body.removeChild(document.getElementById(id)); } let div = document.createElement('div'); div.id = id; div.style.pointerEvents = 'none'; div.style.top = '44px'; div.style.left = '-40px'; div.style.bottom = '50px'; div.style.right = '0px'; div.style.position = 'fixed'; div.style.zIndex = '100000'; div.style.zoom = '0.6'; //設置縮放 div.style.opacity = '0.5'; //設置透明度 div.style.background = 'url(' + path + ') left top repeat'; document.body.appendChild(div); return id; // #endif // #ifdef APP-PLUS if (plus.nativeObj.View.getViewById(id) !== null) { plus.nativeObj.View.getViewById(id).close(); } uni.getSystemInfo({ success: function (res) { //水印排列行數(shù) let row = Math.floor(res.windowHeight / uni.upx2px(250)); let tarArr = []; for(let i = 0; i < row; i++) { for(let j = 0; j < 3; j++){ tarArr.push({ tag: 'img', src: path, position: { top: (uni.upx2px(255) * i) + 'px', left: (uni.upx2px(255) * j) + 'px', width: uni.upx2px(255) + 'px', height: uni.upx2px(255) + 'px' } }); } } var watermarkView = new plus.nativeObj.View(id, { top:'70px', left:'0px', right: '0px', bottom: '50px' }, tarArr); //攔截View控件的觸屏事件,將事件穿透給下一層view watermarkView.interceptTouchEvent(false); watermarkView.show(); } }); // #endif } export default watermark;
圖片
以上就是uni-app實現(xiàn)全局水印示例詳解的詳細內(nèi)容,更多關(guān)于uni-app全局水印的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
javascript如何判斷數(shù)組內(nèi)元素是否重復的方法集錦
javascript如何判斷數(shù)組內(nèi)元素是否重復的方法集錦...2007-02-02使用JS實現(xiàn)jQuery的addClass, removeClass, hasClass函數(shù)功能
這篇文章主要介紹了使用JS實現(xiàn)jQuery的addClass, removeClass, hasClass函數(shù)功能,需要的朋友可以參考下2014-10-10JavaScript實現(xiàn)復制文章自動添加版權(quán)
自己辛辛苦苦寫的文章,輕易就被別人復制-粘貼去了,是不是很傷心呢?小編今天給大家整理了兩個方法,讓別人復制自己的文章時,自動在文章的結(jié)尾添加自己的版權(quán)信息。2016-08-08純JavaScript實現(xiàn)的完美漸變彈出層效果代碼
對于Web項目開發(fā)尤其是前臺UI的設計而言,用戶體驗至關(guān)重要,因為它直接關(guān)系到項目的成敗,簡潔,平滑,優(yōu)雅的設計永遠能夠受到用戶的青睞。2010-04-04Layui數(shù)據(jù)表格之獲取表格中所有的數(shù)據(jù)方法
今天小編就為大家分享一篇Layui數(shù)據(jù)表格之獲取表格中所有的數(shù)據(jù)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08