javascript - HTML5 Scratch Card - Stack Overflow

I'm trying to setup a wee scratch card game, where there are several panels and you drag over or t

I'm trying to setup a wee scratch card game, where there are several panels and you drag over or touch (ipad, smartphone etc) to scratch and reveal the image beneath.

I'm not a JS guru so I've searched extensively and found what I believe is the best script:


Uses canvas and jQuery. It also lets you see the percentage scratched but it doesn't work on mobile.

I'm looking at the JS but don't know how to go about adding touch events to the script: .js

?

I'm trying to setup a wee scratch card game, where there are several panels and you drag over or touch (ipad, smartphone etc) to scratch and reveal the image beneath.

I'm not a JS guru so I've searched extensively and found what I believe is the best script:

http://www.websanova./tutorials/jquery/html5-jquery-scratch-pad-plugin
Uses canvas and jQuery. It also lets you see the percentage scratched but it doesn't work on mobile.

I'm looking at the JS but don't know how to go about adding touch events to the script: https://github./websanova/wScratchPad/blob/master/wScratchPad.js

?

Share Improve this question edited Aug 9, 2012 at 5:33 Quadrant6 asked Aug 9, 2012 at 5:22 Quadrant6Quadrant6 1,2352 gold badges16 silver badges25 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 1

I don't use jQuery much, so not sure how to extend jQuery extensions per se, but looking at the example code on github you want to add changes to these lines (110-140):

this.sp =
$('<div></div>')
.css({cursor: 'default', position: 'relative'})
.append(
    $(this.canvas)
    .attr('width', this.settings.width + 'px')
    .attr('height', this.settings.height + 'px')
    .css({cursor: 'default'})
    .mousedown(function(e)
    {
        e.preventDefault();
        e.stopPropagation();
        $this.scratch = true;
        $this.scratchFunc(e, $this, 'Down');
    })
)

$(document)
.mousemove(function(e)
{
    if($this.scratch) $this.scratchFunc(e, $this, 'Move');
})
.mouseup(function(e)
{
    //make sure we are in draw mode otherwise this will fire on any mouse up.
    if($this.scratch)
    {
        $this.scratch = false;
        $this.scratchFunc(e, $this, 'Up');
    }
});

If you modify or duplicate this block, and add touchevents replicating the functionality of the mousedown, mousemove and mouseup handlers, you should be mostly there.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745461045a4628710.html

相关推荐

  • javascript - HTML5 Scratch Card - Stack Overflow

    I'm trying to setup a wee scratch card game, where there are several panels and you drag over or t

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信