给后台网页加水印功能

JS代码

function addWaterMarker(str){


    var can = document.createElement('canvas');
    var body = document.body;

    body.appendChild(can);

    can.width=400;
    can.height=200;
    can.style.display='none';


    var cans = can.getContext('2d');
    cans.rotate(-20*Math.PI/180);
    cans.font = "16px Microsoft JhengHei";
    cans.fillStyle = "rgba(17, 17, 17, 0.50)";
    cans.textAlign = 'left';
    cans.textBaseline = 'Middle';
    cans.fillText(str,can.width/3,can.height/2);

    body.style.backgroundImage="url("+can.toDataURL("image/png")+")";

}

在页面调用就可以看到效果了

 

posted @ 2018-07-27 14:57  郁冬  阅读(1431)  评论(0编辑  收藏  举报