刮擦以揭示隐藏在下面 图像 jQuery橡皮擦

  • 源码大小:278.52KB
  • 所需积分:1积分
  • 源码编号:19JP-3383
  • 浏览次数:530次
  • 最后更新:2023年06月07日
  • 所属栏目:其他
本站默认解压密码:19jp.com 或 19jp_com

简介

一个jQuery支持的橡皮擦工具,使您能够使用鼠标移动或触摸手势来抓取图像,以显示下面隐藏的图像,就像抓取卡一样。

这通常用于推广要求用户在查看附加信息之前采取行动的产品或服务。

参见:

  • jQuery插件用于HTML5基于画布的Scratchcard-ScratchIt
  • 纯JavaScript触控刮刮卡
  • 支持触摸的虚拟刮刮卡,带有JavaScript和CanvasâTouch2Revelal

如何使用它:

1.包括jQuery库和jquery.eraser.js查询页面上的脚本。

  1. <script src="/path/to/cdn/jquery.min.js"></script>
  2. <script src="/path/to/jquery.eraser.js"></script>

2.将重叠的图像添加到页面中。

  1. <img id="overlay" src="overlay.jpg" />
  2. <img id="underneath" src="underneath.png" />
  1. #overlay {
  2. position: absolute;
  3. top: 0px;
  4. left: 0px;
  5. z-index: 1;
  6. }
  7.  
  8. #underneath {
  9. position: absolute;
  10. top: 0px;
  11. left: 0px;
  12. z-index: 2;
  13. }

3.调用“underground”图像上的函数并完成。

  1. $('#underneath').eraser({
  2. // ...
  3. });

4.指定笔刷大小。默认值:40。

  1. $('#underneath').eraser({
  2. size: 20,
  3. });

5.当达到擦除比率时触发一个功能。

  1. $('#underneath').eraser({
  2. completeRatio: .65,
  3. completeFunction: myFunction,
  4. });

6.API方法。

  1. // erases all canvas content
  2. $('#underneath').eraser( 'clear' );
  3.  
  4. // revert back to original content
  5. $('#underneath').eraser( 'reset' );
  6.  
  7. // change the brush size
  8. $('#underneath').eraser( 'size', 80 );
  9.  
  10. // enable or disable erasing
  11. $('#underneath').eraser( 'enable/disable' );
  12.  
  13. // returns true if the eraser is enabled
  14. $('#underneath').eraser( 'enabled' );

预览截图