1 Star 0 Fork 0

汤浪 / simple-water

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

simple-water

一款用于生成水印的JS插件,使用简单,支持TS

核心代码

  • 设置水印

    // 方式1:水印'admin' 将设置到整个html标签上
    setWaterMark('admin')
    
    // 方式2:水印'admin' 将设置到id为app的盒子上
    setWaterMark('admin', '#app')
    
    // 方式3:水印'admin' 将设置到div变量所指向的DOM盒子上
    const div = document.querySelector('#app')
    setWaterMark('admin', div)
  • 移除水印

    // 移除之前添加的水印
    removeWaterMark()

使用步骤

  1. 安装

    npm i simple-water
    
    yarn add simple-water
    
    pnpm add simple-water
  2. 导入

    import { setWaterMark  } from "simple-water";
  3. 使用(以vue3项目为例)

    <script setup lang="ts">
    import { onMounted } from "vue";
    import { setWaterMark  } from "simple-water";
    
    onMounted(()=>{
      setWaterMark('admin')
    })
    </script>

    呈现效果

    DEMO

配置对象

支持传递配置项进行配置setWaterMark(水印文本, DOM或选择器, 配置对象)

核心代码如下:

// 完整的配置对象,其中每个属性都是非必须的
const option = {
        blockWdith: 150,      // 每块宽度
        blockHeight: 80,      // 每块高度 
        rotate: 20,     	  // 文字倾斜角度
        font: "18px Vedana",  // 水印文字字体
        fillStyle: '#666666', // 水印文字颜色
        zIndex: 10000,        // 水印层级
    	opacity: 0.08         // 水印透明度
}

// 方式1:水印'admin' 将设置到整个html标签上
setWaterMark('admin', null, option)

// 方式2:水印'admin' 将设置到id为app的盒子上
setWaterMark('admin', '#app', option)

// 方式3:水印'admin' 将设置到div变量所指向的DOM盒子上
const div = document.querySelector('#app')
setWaterMark('admin', div, option)

其中option配置项可以写到一个.json的配置文件中再导入使用

仓库地址

gitee上的仓库地址:https://gitee.com/tang-lang/simple-water

MIT License Copyright (c) 2024 汤浪 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一款用于生成水印的JS插件,使用简单,支持TS 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/tang-lang/simple-water.git
git@gitee.com:tang-lang/simple-water.git
tang-lang
simple-water
simple-water
main

搜索帮助

53164aa7 5694891 3bd8fe86 5694891