admin管理员组文章数量:1426244
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 badges1 Answer
Reset to default 1I 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.
本文标签: javascriptHTML5 Scratch CardStack Overflow
版权声明:本文标题:javascript - HTML5 Scratch Card - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745461045a2659326.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论