刮刮卡刮奖效果



//代码框架

<div class="content-box">
    <div id="demo1" class="scratchpad"></div>
    <div id="demo1-percent">&nbsp;</div>
    <script type="text/javascript">
                $(‘#demo1‘).wScratchPad({
                      size:25, //笔刷大小
                      fg: ‘./images/canvas-image.png‘,//图片背景
                      bg: ‘./images/openprize.png‘,//中奖图片
                     // realtime    : true,
                     ‘cursor‘: ‘crosshair‘,//刮奖橡皮图片
                     scratchDown: function(e, percent){
                            $(this.canvas).css(‘margin-right‘, $(this.canvas).css(‘margin-right‘) == "0px" ? "1px" : "0px");
                      },
                     scratchMove: function(e, percent){
                            $(this.canvas).css(‘margin-right‘, $(this.canvas).css(‘margin-right‘) == "0px" ? "1px" : "0px");
                            if (percent > 5) {
                                   this.clear();
                                   $(‘#infor-btn‘).addClass("infor-select");
                                   setTimeout("xxx()",1000)
                                 //  $(‘#demo1-percent‘).html("<img src=‘images/area-open.png‘ />");
                                  // $(‘#demo1-percent‘).css("background",‘url(images/area.png) no-repeat scroll‘)
                                            }
                      },
                scratchUp: function(e, percent){
                      $(this.canvas).css(‘margin-right‘, $(this.canvas).css(‘margin-right‘) == "0px" ? "1px" : "0px");
                }
        });
        function xxx(){
                $(‘#demo1-percent‘).html("<img src=‘images/area-open.png‘ />");
        }

  </script>
  </div>
.scratchpad {
height: 178px;
position: absolute;
right: 6px;
top: 110px;
width: 294px;
}

 


/*插件框架*//*! wScratchPad - v2.1.0 - 2014-04-14 */
 !
function(a) {
    "use strict";
    function b(b, c) {
        this.$el = a(b),
        this.options = c,
        this.init = !1,
        this.enabled = !0,
        this._generate()
    }
    b.prototype = {
        _generate: function() {
            return a.support.canvas ? (this.canvas = document.createElement("canvas"), this.ctx = this.canvas.getContext("2d"), "static" === this.$el.css("position") && this.$el.css("position", "relative"), this.$img = a(‘<img src=""/>‘).attr("crossOrigin", "").css({
                position: "absolute",
                width: "100%",
                height: "100%"
            }), this.$scratchpad = a(this.canvas).css({
                position: "absolute",
                width: "100%",
                height: "100%"
            }), this.$scratchpad.bindMobileEvents(), this.$scratchpad.mousedown(a.proxy(function(b) {
                return this.enabled ? (this.canvasOffset = a(this.canvas).offset(), this.scratch = !0, void this._scratchFunc(b, "Down")) : !0
            },
            this)).mousemove(a.proxy(function(a) {
                this.scratch && this._scratchFunc(a, "Move")
            },
            this)).mouseup(a.proxy(function(a) {
                this.scratch && (this.scratch = !1, this._scratchFunc(a, "Up"))
            },
            this)), this._setOptions(), this.$el.append(this.$img).append(this.$scratchpad), this.init = !0, void this.reset()) : (this.$el.append("Canvas is not supported in this browser."), !0)
        },
        reset: function() {
            var b = this,
            c = Math.ceil(this.$el.innerWidth()),
            d = Math.ceil(this.$el.innerHeight()),
            e = window.devicePixelRatio || 1;
            this.pixels = c * d,
            this.$scratchpad.attr("width", c).attr("height", d),
            this.canvas.setAttribute("width", c * e),
            this.canvas.setAttribute("height", d * e),
            this.ctx.scale(e, e),
            this.pixels = c * e * d * e,
            this.$img.hide(),
            this.options.fg && ("#" === this.options.fg.charAt(0) ? (this.ctx.fillStyle = this.options.fg, this.ctx.beginPath(), this.ctx.rect(0, 0, c, d), this.ctx.fill(), this.$img.show()) : a(new Image).attr("src", this.options.fg).load(function() {
                b.ctx.drawImage(this, 0, 0, c, d),
                b.$img.show()
            })),
            //setTimeout(function(){
            this.options.bg && ("#" === this.options.bg.charAt(0) ? this.$el.css("backgroundColor", this.options.bg) : (this.$el.css("backgroundColor", ""), this.$img.attr("src", this.options.bg)))//中奖图片
            //}, 300)
        },
        clear: function() {
            this.ctx.clearRect(0, 0, Math.ceil(this.$el.innerWidth()), Math.ceil(this.$el.innerHeight()))
        },
        enable: function(a) {
            this.enabled = a === !0 ? !0: !1
        },
        destroy: function() {
            this.$el.children().remove(),
            a.removeData(this.$el, "wScratchPad")
        },
        _setOptions: function() {
            var a,
            b;
            for (a in this.options) this.options[a] = this.$el.attr("data-" + a) || this.options[a],
            b = "set" + a.charAt(0).toUpperCase() + a.substring(1),
            this[b] && this[b](this.options[a])
        },
        setBg: function() {
            this.init && this.reset()
        },
        setFg: function() {
            this.setBg()
        },
        setCursor: function(a) {
            this.$el.css("cursor", a)
        },
        _scratchFunc: function(a, b) {
            a.pageX = Math.floor(a.pageX - this.canvasOffset.left),
            a.pageY = Math.floor(a.pageY - this.canvasOffset.top),
            this["_scratch" + b](a),
            (this.options.realtime || "Up" === b) && this.options["scratch" + b] && this.options["scratch" + b].apply(this, [a, this._scratchPercent()])
        },
        _scratchPercent: function() {
            for (var a = 0, b = this.ctx.getImageData(0, 0, this.canvas.width, this.canvas.height), c = 0, d = b.data.length; d > c; c += 4) 0 === b.data[c] && 0 === b.data[c + 1] && 0 === b.data[c + 2] && 0 === b.data[c + 3] && a++;
            return a / this.pixels * 100
        },
        _scratchDown: function(a) {
            this.ctx.globalCompositeOperation = "destination-out",
            this.ctx.lineJoin = "round",
            this.ctx.lineCap = "round",
            this.ctx.strokeStyle = this.options.color,
            this.ctx.lineWidth = this.options.size,
            this.ctx.beginPath(),
            this.ctx.arc(a.pageX, a.pageY, this.options.size / 2, 0, 2 * Math.PI, !0),
            this.ctx.closePath(),
            this.ctx.fill(),
            this.ctx.beginPath(),
            this.ctx.moveTo(a.pageX, a.pageY)
        },
        _scratchMove: function(a) {
            this.ctx.lineTo(a.pageX, a.pageY),
            this.ctx.stroke()
        },
        _scratchUp: function() {
            this.ctx.closePath()
        }
    },
    a.support.canvas = document.createElement("canvas").getContext,
    a.fn.wScratchPad = function(c, d) {
        function e() {
            var d = a.data(this, "wScratchPad");
            return d || (d = new b(this, a.extend(!0, {},
            c)), a.data(this, "wScratchPad", d)),
            d
        }
        if ("string" == typeof c) {
            var f,
            g = [],
            h = (void 0 !== d ? "set": "get") + c.charAt(0).toUpperCase() + c.substring(1),
            i = function() {
                f.options[c] && (f.options[c] = d),
                f[h] && f[h].apply(f, [d])
            },
            j = function() {
                return f[h] ? f[h].apply(f, [d]) : f.options[c] ? f.options[c] : void 0
            },
            k = function() {
                f = a.data(this, "wScratchPad"),
                f && (f[c] ? f[c].apply(f, [d]) : void 0 !== d ? i() : g.push(j()))
            };
            return this.each(k),
            g.length ? 1 === g.length ? g[0] : g: this
        }
        return c = a.extend({},
        a.fn.wScratchPad.defaults, c),
        this.each(e)
    },
    a.fn.wScratchPad.defaults = {
        size: 5,
        bg: "#cacaca",
        fg: "#6699ff",
        realtime: !0,
        scratchDown: null,
        scratchUp: null,
        scratchMove: null,
        cursor: "crosshair"
    },
    a.fn.bindMobileEvents = function() {
        a(this).on("touchstart touchmove touchend touchcancel",
        function(a) {
            var b = a.changedTouches || a.originalEvent.targetTouches,
            c = b[0],
            d = "";
            switch (a.type) {
            case "touchstart":
                d = "mousedown";
                break;
            case "touchmove":
                d = "mousemove",
                a.preventDefault();
                break;
            case "touchend":
                d = "mouseup";
                break;
            default:
                return
            }
            var e = document.createEvent("MouseEvent");
            e.initMouseEvent(d, !0, !0, window, 1, c.screenX, c.screenY, c.clientX, c.clientY, !1, !1, !1, !1, 0, null),
            c.target.dispatchEvent(e)
        })
    }
} (jQuery);

刮刮卡效果插件及用法~

刮刮卡刮奖效果

时间: 2024-10-09 23:38:47

刮刮卡刮奖效果的相关文章

HTML5实现刮奖效果

原文:HTML5实现刮奖效果 要实现刮奖效果,最重要的是要找到一种方法:当刮开上层的涂层是就能看到下层的结果.而HTML5的canvas API中有一个属性globalCompositeOperation,这个属性有多个值,而实现刮奖效果要用到的值就是destination-out.意思就是:在已有内容和新图形不重叠的地方,已有内容保留,所有其他内容成为透明.这样可能不好理解,后面实现的时候会解释.有了globalCompositeOperation这个属性,实现过程就很简单了. 我们需要有两个

canvas刮奖效果

上次写刮奖效果都一年前了,那时候还是百度找的源码给改的,自己其实也是迷迷糊糊的,这次因为让妹子写,然后想着自己也重新整理下. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0,

简单入门canvas - 通过刮奖效果来学习

一 .前言 一直在做PC端的前端开发,从互联网到行业软件.最近发现移动端已经成为前端必备技能了,真是不能停止学习.HTML5新增的一些东西,canvas是用的比较多也比较复杂的一个,简单的入门了一下,通过一个刮奖效果来学习. 二.canvas基础 本文的目标是做一个刮奖效果,但是如果都不知道canvas是怎么回事,那么肯定也无法进行下去,所以先讲讲canvas基础吧. 首先,该怎么理解canvas,思来想去,最好的理解办法应该就是把canvas理解为一个空白的画纸,一张你可以在上面画画的纸. 然

iOS UIcollectionView 实现卡牌翻转效果

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.title = @"卡牌翻转效果"; self.edgesForExtendedLayout = UIRectEdgeNone; [self.view addSubview:self.collectionView]; NSArray * arr =

1689熊猫彩票增加视频版本(PC+手机端、带有视频动画开奖效果) ——含手机端、前后台带极速彩

2018最新版彩票现金盘,新增pc端+手机端视频动画运行环境:php5.2+mysql源码类别:两面盘界面语言:繁体中文源码授权:无加密文件及认证授权,永久性可直接使用.版本支持:PC/WAP网页版编程语言:PHP1689熊猫增加视频版本(PC+手机端.带有视频动画开奖效果) --含手机端.前后台带极速彩由大神源码论坛dsluntan.com独家发布!!! 原文地址:http://blog.51cto.com/13855350/2136921

HTML5模仿刮奖效果-页面涂抹消失插件wScratch

前言 HTML5的canvas有很多应用点,如绘画板.图形绘制.游戏交互.彩票刮刮乐等,除了这些,还有个比较好的点就是主页涂抹一部分之后,页面消失进入主要内容. wScratch是一个模拟刮刮卡的jQuery插件,可以设置刮开纯色或者图像. 演示 显示刮卡百分比 到达一定百分比清空 属性设置 可用的属性,以下是默认值 1 2 3 4 5 6 7 8 9 10 $('#elem').wScratchPad({ size        : 5,          // The size of the

android刮刮奖效果

自定义View盖在textView上 import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; impo

canvas 利用canvas中的globalCompositeOperation 绘制刮奖 效果

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <style> body { height: 1000px; } </style> </head> <body> <div style="position: relative; width: 300p

使用HTML5实现刮刮卡效果

原文地址:http://www.phpthinking.com/archives/525 你玩过刮刮卡么?一不小心可以中奖的那种.今天我给大家分享一个基于HTML5技术实现的刮刮卡效果,在PC上只需按住鼠标,在手机上你只需按住指头,轻轻刮去图层就可以模拟真实的刮奖效果. 我们利用HTML5的画布Canvas,结合其提供的API,在Canvas元素上绘制一个灰色蒙层,然后通过检测用户鼠标移到和手势来绘制一个透明的图形,这样就能看到Canvas背景下的真实图片,就达到刮刮卡效果. 点击下载源码 HT