Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

realtime is slow in mobile and here's my workaround #47

Open
tominhuang opened this issue Mar 9, 2015 · 1 comment
Open

realtime is slow in mobile and here's my workaround #47

tominhuang opened this issue Mar 9, 2015 · 1 comment

Comments

@tominhuang
Copy link

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.
            });
@Gee63
Copy link

Gee63 commented Feb 1, 2016

worked for me :) Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants