微信擦出插件

https://github.com/boblemarin/jQuery.eraser

 

这是一个jquery插件,实现橡皮擦功能,可使得当前图像被擦除,鼠标和触摸都可。

用法:

首先自然要引入jquery和本插件

将图片或canvas变成一个可擦除画布:

1
$('#yourImage').eraser();

指定一个画笔大小,默认值为40:

1
2
3
$('#yourImage').eraser( { size: 30 } );
// 也可以用下面方法设置画笔大小 :
// $('#yourImage').eraser( 'size', 30  );

重置帆布(回原始图像):

1
$('#yourImage').eraser('reset');

全部擦除:

1
$('#yourImage').eraser('clear');

当图像被擦除50%时,调用回调函数:

1
2
3
4
$('#yourImage').eraser( {
    completeRatio: .5,
    completeFunction: showResetButton
});

跟踪擦除面积:

1
var progress = $('#yourImage').eraser('progress'); // 返回值0到1之间

擦除面积回调:

1
2
3
4
5
$('#yourImage').eraser( {
    progressFunction: function(p) {
        console.log(Math.round(p * 100) + '%');
    }
});

经测试,移动端兼容性达100%,目前未遇到不适用的机型

posted @ 2015-10-28 15:48  王霸天  阅读(202)  评论(0)    收藏  举报