HTML5中如何實(shí)現(xiàn)網(wǎng)頁水印SDK

這篇文章將為大家詳細(xì)講解有關(guān)HTML5中如何實(shí)現(xiàn)網(wǎng)頁水印SDK,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

創(chuàng)新互聯(lián)專注于海倫網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供海倫營銷型網(wǎng)站建設(shè),海倫網(wǎng)站制作、海倫網(wǎng)頁設(shè)計(jì)、海倫網(wǎng)站官網(wǎng)定制、微信小程序開發(fā)服務(wù),打造海倫網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供海倫網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

網(wǎng)頁水印SDK,實(shí)現(xiàn)思路

1.能更具獲取到的當(dāng)前用戶信息,如名字,昵稱,ID等,生成水印
2.生成一個(gè)Canvas,覆蓋整個(gè)窗口,并且不影響其他元素
3.可以修改字體間距,大小,顏色
4.不依賴Jquery
5.需要防止用戶手動(dòng)刪除這個(gè)Canvas

實(shí)現(xiàn)分析

初始參數(shù)

size: 字體大小
color: 字體顏色
id: canvasId
text: 文本內(nèi)容
density: 間距
clarity: 清晰度
supportTip: Canvas不支持的文字提示

生成Canvas

根據(jù)id生成Canvas,畫布大小為window.screen大小,若存在原有老的Canvas,清除并重新生成。

畫布固定定位在可視窗口,z-index為-1

  let body = document.getElementsByTagName('body');
    let canvas = document.createElement('canvas');
    canvas.style.cssText= 'position: fixed;width: 100%;height: 100%;left:0;top:0;z-index: -1;';
    body[0].appendChild(canvas);

指紋生成算法

 let canvas = document.getElementById(this.params.id);
      let cxt = canvas.getContext('2d');
      let times = window.screen.width * this.params.clarity / this.params.density;//橫向文字填充次數(shù)
      let heightTimes = window.screen.height * this.params.clarity * 1.5/ this.params.density; //縱向文字填充次數(shù)
      cxt.rotate(-15*Math.PI/180); //傾斜畫布
   
      for(let i = 0; i < times; i++) {
        for(let j = 0; j < heightTimes; j++) {
          cxt.fillStyle = this.params.color;
          cxt.font = this.params.size + ' Arial';
          cxt.fillText(this.params.text, this.params.density*i, j*this.params.density);
        }
      }

防止用戶刪除

使用定時(shí)器,定時(shí)檢查指紋是否存在

  let self = this;
    window.setInterval(function(){
    if (!document.getElementById(self.params.id)) {
    self._init();
    }
    }, 1000);

項(xiàng)目編譯

使用glup編譯

  var gulp = require('gulp'),
        uglify = require("gulp-uglify"),
        babel = require("gulp-babel");
    gulp.task('minify', function () {
        return gulp.src('./src/index.js') // 要壓縮的js文件
        .pipe(babel())
        .pipe(uglify())
        .pipe(gulp.dest('./dist')); //壓縮后的路徑
    });

指紋效果

HTML5中如何實(shí)現(xiàn)網(wǎng)頁水印SDK

關(guān)于“HTML5中如何實(shí)現(xiàn)網(wǎng)頁水印SDK”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請把它分享出去讓更多的人看到。

網(wǎng)站名稱:HTML5中如何實(shí)現(xiàn)網(wǎng)頁水印SDK
鏈接地址:http://muchs.cn/article4/ghssie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、定制網(wǎng)站、網(wǎng)站策劃全網(wǎng)營銷推廣、網(wǎng)站導(dǎo)航外貿(mào)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名