uni-app實(shí)現(xiàn)全局水印示例詳解
使用方法
1、在App.vue中引入并設(shè)置水印
2、本例子使用的水印圖片是250*250px的,可以根據(jù)需要自己調(diào)整樣式
3、watermark.js內(nèi)容見(jiàn)下方
<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'; //設(shè)置縮放
div.style.opacity = '0.5'; //設(shè)置透明度
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實(shí)現(xiàn)全局水印示例詳解的詳細(xì)內(nèi)容,更多關(guān)于uni-app全局水印的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
TypeScript開(kāi)發(fā)小狀況記錄之選且只選一個(gè)
在開(kāi)發(fā)中需要定義一個(gè)對(duì)象的類(lèi)型,此類(lèi)型必須包含某n個(gè)字段中的其中一種,這篇文章主要給大家介紹了關(guān)于TypeScript開(kāi)發(fā)小狀況記錄之選且只選一個(gè)的相關(guān)資料,需要的朋友可以參考下2022-10-10
js中的hasOwnProperty和isPrototypeOf方法使用實(shí)例
這篇文章主要介紹了js中的hasOwnProperty和isPrototypeOf方法使用實(shí)例,需要的朋友可以參考下2014-06-06
JS中Iframe之間傳值及子頁(yè)面與父頁(yè)面應(yīng)用
用iframe做系統(tǒng)框架,相信很多朋友都有這樣的經(jīng)歷吧,接下來(lái)將為你詳細(xì)介紹下JS中Iframe之間傳值應(yīng)用,感興趣的你可以參考下哈,希望可以幫助到你2013-03-03
微信小程序遍歷Echarts圖表實(shí)現(xiàn)多個(gè)餅圖
這篇文章主要介紹了微信小程序遍歷Echarts圖表實(shí)現(xiàn)多個(gè)餅圖,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
JavaScript delete操作符應(yīng)用實(shí)例
delete 運(yùn)算符 從對(duì)象中刪除一個(gè)屬性,或從數(shù)組中刪除一個(gè)元素。2009-01-01

