js添加文字水印

function watermarkWord(watermarkImg , watermarkText) {
        var screenHeight = window.screen.height
        var watermarkImg = watermarkImg ;
        var watermarkText =  watermarkText;

        if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/9./i) == "9.") {
            var step = 180 / 480 * screenHeight;
            for (var i = 0; i <= parseInt($("body").height() / step); i++) {
                $('body').append('<div style="z-index:-999;width:100%;text-align:center;opacity:0.2;color:#000;position:absolute;top:' + step * (i) + 'px;font-size:2em;transform:rotate(-30deg); -ms-transform:rotate(-30deg); -o-tranform:rotate(-30deg); -webkit-transform:rotate(-30deg); -moz-transform:rotate(-30deg);filter:progid:DXImageTransform.Microsoft.Alpha(opacity=10));">' + watermarkText + '<br /><img style="width:8em;" src="' + watermarkImg + '" /></div>');
            }
        } else {
            var step = 180 / 480 * screenHeight;
            for (var i = 0; i <= parseInt($("body").height() / step); i++) {
                $('body').append('<div style="z-index:-999;width:100%;text-align:center;opacity:0.5;color:#000;position:absolute;top:' + step * (i) + 'px;font-size:2em;transform:rotate(-30deg); -ms-transform:rotate(-30deg); -o-tranform:rotate(-30deg); -webkit-transform:rotate(-30deg); -moz-transform:rotate(-30deg);filter:progid:DXImageTransform.Microsoft.Alpha(opacity=10) progid:DXImageTransform.Microsoft.Matrix(sizingMethod=\'auto expand\', M11=0.866025404, M12=0.5, M21=-0.5, M22=0.866025404);">' + watermarkText + '<br /><img  style="width:8em;" src="' + watermarkImg + '" /></div>');
            }
        }
    }
watermarkWord("../img/1_143855_3.jpg","这是用来测试的");

  

posted @ 2019-05-31 17:11  董七  阅读(574)  评论(0编辑  收藏  举报