npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

scratch-me

v1.0.0

Published

Append a scratchable card in html.

Downloads

9

Readme

ScratchMe

一个基于canvas实现“刮刮卡”功能的js库。

安装

使用npm:

$ npm install scratch-me

直接引入<script>:

<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/scratch-me.min.js"></script>

示例

查看demo页面

快速开始

首先需要在html中放置一个容器:

<div class="container"></div>

在js中引入ScratchCanvas并将容器元素传递给构造函数后调用实例的init方法即可:

import ScratchMe from 'scratch-me'

const containerElm = document.querySelector('.container')
const scratchMe = new ScratchMe(containerElm)
scratchMe.init()

配置

在创建实例时通过向第二个参数传入一个对象进行配置:

const scratchMe = new ScratchMe(elm, {/* 配置项... */})
scratchMe.init()

可用配置项:

选项名 | 类型 | 默认值 | 可选值 | 描述 :-: | :-: | :-: | - | - bg | String | null | 有效的图片url | 若bg的值为有效的图片url,则会在蒙层下自动生成背景 mask | String | #ccc | 有效的颜色字符串或图片url | 蒙层的填充内容 width | Number | null | 正整数 | 生成的canvas标签的width属性值,不设置该值时canvas的width将会是容器元素的实际宽度 height | Number | null | 正整数 | 生成的canvas标签的height属性值,不设置该值时canvas的height将会是容器元素的实际高度 brushSize | Number | 25 | 正整数 | 笔刷(半径)大小 maxPercent | Number | 100 | 正整数 | 激活百分比 到该值就显示结果 scratchArea | Obj | {startX:0, startY:0, areaWidth:0, areaHeight:0} | - | 设置该区域内可以“刮除”。startX,startY 起点;areaWidth:区域宽度;areaHeight:区域长度 brushPress | Number | 1 | 0~1之间任意数字 | 笔刷压强 onCreated | Function | null | - | 实例初始化完毕被插入到dom节点后的回调函数 onScratch | Function | null | - | "刮除"蒙层时的回调函数,接收一个参数,该参数值为已"刮除"面积与总面积的百分比(对于一个像素掉,"已刮除"的定义是该像素点透明度小于0.25,而不是该像素点必须被mousedown/mousemove等事件处理过) onEnd | Function | null | - | "刮除"蒙层结束后 回调函数,接收一个参数,该参数值为已"刮除"面积与总面积的百分比(对于一个像素掉,"已刮除"的定义是该像素点透明度小于0.25,而不是该像素点必须被mousedown/mousemove等事件处理过) throttleWait | Number | 0 | 正数 | 节流函数的间隔时间参数,如果在使用过程中发现明显卡顿(刮除不连续属于正常现象)可以尝试调高该参数值

实例API

API名 | 描述 -|- init() | 初始化并将生成的canvas插入到创建实例时传入的容器元素节点中,插入后会触发回调函数onCreated

License

MIT