wScratchPad
wScratchPad copied to clipboard
realtime is slow in mobile and here's my workaround
In desktop, the performance of using realtime and getting percent scratched is fair enough. But in mobile, it's slow getting percent in realtime.
My workaround is adding a line around 183 line.
_scratchFunc: function (e, event) {
e.pageX = Math.floor(e.pageX - this.canvasOffset.left);
e.pageY = Math.floor(e.pageY - this.canvasOffset.top);
this['_scratch' + event](e);
if (this.options.realtime || event === 'Up') {
if (this.options['scratch' + event]) {
this.options['scratch' + event].apply(this, [e, this._scratchPercent()]);
}
}
+ this.options['myFunc'].apply(this, [e, event]);
},
Usage:
var count = 0;
$('#elem').wScratchPad({
size : 55, // The size of the brush/scratch.
bg : 'images/bonus/0.jpg', // Background (image path or hex color).
fg : 'images/Scraping.jpg', // Foreground (image path or hex color).
realtime : true, // Calculates percentage in realitime.
scratchDown : null,
scratchUp : null,
scratchMove : null,
+ myFunc : function() {
count++;
if (count > 100) {
this.clear();
}
},
cursor : 'crosshair' // Set cursor.
});
worked for me :) Thanks!