html5怎么在刮奖上面加水印

html-css08

html5怎么在刮奖上面加水印,第1张

我的想法是在上面加一个DIV绝对定位,DIV里面是一堆宽和高都为1个像素的,鼠标移到小的像素的DIV上时,让他的背景和透明度不见,这样下面刮奖的内容就可以显示出来了,因为DIV又小又多,所以可能需要来回移动鼠标,模拟刮奖的过程

<!DOCTYPE html>

<html>

<head>

  <meta http-equiv="content-type" content="text/html charset=UTF-8">

  <title> - jsFiddle demo by artwl</title>

  

  <script type='text/javascript' src='/js/lib/dummy.js'></script>

  

  

  

  

  <link rel="stylesheet" type="text/css" href="/css/result-light.css">

  

  <style type='text/css'>

    body{

    height:1000px

}

#lotteryContainer {

    position:relative

    width: 300px

    height:100px

}

#drawPercent {

    color:#F60

}

  </style>

  

</head>

<body>

  <button id="freshBtn">刷新</button><label>已刮开 <span id="drawPercent">0%</span> 区域。</label>

<div id="lotteryContainer"></div>

  

<script type='text/javascript'>//<![CDATA[ 

function Lottery(id, cover, coverType, width, height, drawPercentCallback) {

    this.conId = id

    this.conNode = document.getElementById(this.conId)

    this.cover = cover

    this.coverType = coverType

    this.background = null

    this.backCtx = null

    this.mask = null

    this.maskCtx = null

    this.lottery = null

    this.lotteryType = 'image'

    this.width = width || 300

    this.height = height || 100

    this.clientRect = null

    this.drawPercentCallback = drawPercentCallback

}

Lottery.prototype = {

    createElement: function (tagName, attributes) {

        var ele = document.createElement(tagName)

        for (var key in attributes) {

            ele.setAttribute(key, attributes[key])

        }

        return ele

    },

    getTransparentPercent: function(ctx, width, height) {

        var imgData = ctx.getImageData(0, 0, width, height),

            pixles = imgData.data,

            transPixs = []

        for (var i = 0, j = pixles.length i < j i += 4) {

            var a = pixles[i + 3]

            if (a < 128) {

                transPixs.push(i)

            }

        }

        return (transPixs.length / (pixles.length / 4) * 100).toFixed(2)

    },

    resizeCanvas: function (canvas, width, height) {

        canvas.width = width

        canvas.height = height

        canvas.getContext('2d').clearRect(0, 0, width, height)

    },

    drawPoint: function (x, y) {

        this.maskCtx.beginPath()

        var radgrad = this.maskCtx.createRadialGradient(x, y, 0, x, y, 30)

        radgrad.addColorStop(0, 'rgba(0,0,0,0.6)')

        radgrad.addColorStop(1, 'rgba(255, 255, 255, 0)')

        this.maskCtx.fillStyle = radgrad

        this.maskCtx.arc(x, y, 30, 0, Math.PI * 2, true)

        this.maskCtx.fill()

        if (this.drawPercentCallback) {

            this.drawPercentCallback.call(null, this.getTransparentPercent(this.maskCtx, this.width, this.height))

        }

    },

    bindEvent: function () {

        var _this = this

        var device = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()))

        var clickEvtName = device ? 'touchstart' : 'mousedown'

        var moveEvtName = device? 'touchmove': 'mousemove'

        if (!device) {

            var isMouseDown = false

            document.addEventListener('mouseup', function(e) {

                isMouseDown = false

            }, false)

        } else {

            document.addEventListener("touchmove", function(e) {

                if (isMouseDown) {

                    e.preventDefault()

                }

            }, false)

            document.addEventListener('touchend', function(e) {

                isMouseDown = false

            }, false)

        }

        this.mask.addEventListener(clickEvtName, function (e) {

            isMouseDown = true

            var docEle = document.documentElement

            if (!_this.clientRect) {

                _this.clientRect = {

                    left: 0,

                    top:0

                }

            }

            var x = (device ? e.touches[0].clientX : e.clientX) - _this.clientRect.left + docEle.scrollLeft - docEle.clientLeft

            var y = (device ? e.touches[0].clientY : e.clientY) - _this.clientRect.top + docEle.scrollTop - docEle.clientTop

            _this.drawPoint(x, y)

        }, false)

        this.mask.addEventListener(moveEvtName, function (e) {

            if (!device && !isMouseDown) {

                return false

            }

            var docEle = document.documentElement

            if (!_this.clientRect) {

                _this.clientRect = {

                    left: 0,

                    top:0

                }

            }

            var x = (device ? e.touches[0].clientX : e.clientX) - _this.clientRect.left + docEle.scrollLeft - docEle.clientLeft

            var y = (device ? e.touches[0].clientY : e.clientY) - _this.clientRect.top + docEle.scrollTop - docEle.clientTop

            _this.drawPoint(x, y)

        }, false)

    },

    drawLottery: function () {

        this.background = this.background || this.createElement('canvas', {

            style: 'position:absoluteleft:0top:0'

        })

        this.mask = this.mask || this.createElement('canvas', {

            style: 'position:absoluteleft:0top:0'

        })

        if (!this.conNode.innerHTML.replace(/[\w\W]| /g, '')) {

            this.conNode.appendChild(this.background)

            this.conNode.appendChild(this.mask)

            this.clientRect = this.conNode ? this.conNode.getBoundingClientRect() : null

            this.bindEvent()

        }

        this.backCtx = this.backCtx || this.background.getContext('2d')

        this.maskCtx = this.maskCtx || this.mask.getContext('2d')

        if (this.lotteryType == 'image') {

            var image = new Image(),

                _this = this

            image.onload = function () {

                _this.width = this.width

                _this.height = this.height

                _this.resizeCanvas(_this.background, this.width, this.height)

                _this.backCtx.drawImage(this, 0, 0)

                _this.drawMask()

            }

            image.src = this.lottery

        } else if (this.lotteryType == 'text') {

            this.width = this.width

            this.height = this.height

            this.resizeCanvas(this.background, this.width, this.height)

            this.backCtx.save()

            this.backCtx.fillStyle = '#FFF'

            this.backCtx.fillRect(0, 0, this.width, this.height)

            this.backCtx.restore()

            this.backCtx.save()

            var fontSize = 30

            this.backCtx.font = 'Bold ' + fontSize + 'px Arial'

            this.backCtx.textAlign = 'center'

            this.backCtx.fillStyle = '#F60'

            this.backCtx.fillText(this.lottery, this.width / 2, this.height / 2 + fontSize / 2)

            this.backCtx.restore()

            this.drawMask()

        }

    },

    drawMask: function() {

        this.resizeCanvas(this.mask, this.width, this.height)

        if (this.coverType == 'color') {

            this.maskCtx.fillStyle = this.cover

            this.maskCtx.fillRect(0, 0, this.width, this.height)

            this.maskCtx.globalCompositeOperation = 'destination-out'

        } else if (this.coverType == 'image'){

            var image = new Image(),

                _this = this

            image.onload = function () {

                _this.maskCtx.drawImage(this, 0, 0)

                _this.maskCtx.globalCompositeOperation = 'destination-out'

            }

            image.src = this.cover

        }

    },

    init: function (lottery, lotteryType) {

        this.lottery = lottery

        this.lotteryType = lotteryType || 'image'

        this.drawLottery()

    }

}

window.onload = function () {

    var lottery = new Lottery('lotteryContainer', '#CCC', 'color', 300, 100, drawPercent)

    lottery.init('http://www.baidu.com/img/bdlogo.gif', 'image')

    

    document.getElementById('freshBtn').onclick = function() {

        drawPercentNode.innerHTML = '0%'

        lottery.init(getRandomStr(10), 'text')

    }

    

    var drawPercentNode = document.getElementById('drawPercent')

    

    function drawPercent(percent) {

        drawPercentNode.innerHTML = percent + '%'

    }

}

function getRandomStr(len) {

    var text = ""

    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

    for( var i=0 i < len i++ )

        text += possible.charAt(Math.floor(Math.random() * possible.length))

    return text

}

//]]>  

</script>

</body>

</html>

亲,看看这个对你有帮助么

问题一:手机邀请函怎么制作? 你说的的应该是基于html5技术的手机邀请函,你说的那种刮一刮效果其实就是html5的擦一擦效果,这个在html5页面是很常见的效果。如果你会html5代码,可以直接编程制作,或者联系第三方来进行开发。

如果你不会代码,但是又有这方面的需要,可以通过maka.im之类的html5制作平台,制作起来比较简单,通过模板组合,添加图文的方式来生成,完成之后就能在手机观看和分享。当然可自定义的地方不多,毕竟是以模板为主,关键是免费。

如果觉得还不错,还望采纳~

问题二:怎么做手机电子邀请函? 是不是要这样的,你可以试试注册一个万能页,微信微博qq都可以发,邮件也可以

问题三:手机微信制作邀请函怎么制作 去百度搜易企秀、兔展在线制作H5的网站根据操作做就行

问题四:手机制作邀请函的软件 可以去应用之星网站来制作邀请函,有模板直接可以使用

问题五:制作邀请函的app 用电脑制作吧,手机上制作的效果肯定不好。

“应用之星”平台还不错,可以制作邀请函的H5页面,支持在微信朋友圈里分享和传播~

楼主不懂继续追问我哈~

问题六:有没有一个软件让我也能制做手机邀请函,带音乐和图片的那种 微信音乐卡可以制作

问题七:微信动态邀请函怎么制作 100分 微信动态邀请函,可以通过第三方平台,比如易企秀、微场景等进行制作,以易企秀为例,以下步骤可以在电脑或者手机上操作,步骤是一样的。

1. 百度搜索易企秀。

2. 打开网页之后注册一个账号。

3. 登录后新建一个情景。

4. 可以从提供的模板中选择,也可以新建一个空白的情景。

5. 在情景中编辑图片和文字。

6. 编辑完毕后还可以添加音乐。

7. 最后保存预览,没有问题就可以将链接发布出来转发到微信了。

问题八:我想发生日邀请函给微信的朋友,怎么在手机上制作和发送。 那我真的能帮助到你了。

你直接去应用之星网站来制作生日邀请函,里面有邀请函的模板,你可以直接拿来使用,在此基础上修改,你可以去试试

问题九:制作邀请函软件 注册万能页吧,邀请函可以加背景音乐啥的,十分钟就做好了,手机电脑都可以发!

问题十:如何用苹果手机制作动画邀请函 用手机制作没有那么多的功能,用网站的制作感觉全面一点,可以试试兔展,微页这些网站