下載 jquery擴(kuò)展wscratchpad.js, 原站的頁面打不開,我這里提供一個下載地址
然后(冷靜),一些沒節(jié)操的博主,直接轉(zhuǎn)別人的文章,驗證的過程都省了,應(yīng)該坑了不是小白。我這里修正一下
在這個擴(kuò)展里面,怎么才能過去用戶的刮開的面積
代碼如下:
$(#wscratchpad3).wscratchpad({
cursor:'', //設(shè)置鼠標(biāo)的樣式
color:'gray' , //設(shè)置覆蓋物的顏色,跟image2功能相斥
width:300,
height:100,
image: //頂部的圖片
// 更多配置相關(guān)的選項請看源碼
scratchup: function(e, percent){
if(percent > 60)
{
alert(sss);
}
}
});
從上面的代碼,看的出來,這個跟網(wǎng)上所謂的教程不一樣,這里獲取刮開的范圍用到函數(shù)不是
scratchmove()
而是
scratchup()
為嘛?看源碼
代碼如下:
scratchfunc: function(e, $this, event)
{
e.pagex = math.floor(e.pagex - $this.canvas_offset.left);
e.pagey = math.floor(e.pagey - $this.canvas_offset.top);
$this['scratch' + event](e, $this);
if(this.settings.realtimepercent || event == up) {
if($this.settings['scratch' + event]) $this.settings['scratch' + event].apply($this, [e, $this.scratchpercentage($this)]);
}
}
這里這個獲取函數(shù)綁定的up 而不是move
更多信息請查看IT技術(shù)專欄