zoukankan      html  css  js  c++  java
  • js addeventlistener 刮刮贴

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
    <style>
    .content,.cover{400px; height:400px; position:absolute; left:50%; top:50%; margin:-200px 0 0 -200px;}
    .content{ font-size:48px; line-height:400px; text-align:center;}
    h3{ text-align:center; line-height:200px;}
    </style>

    </head>

    <body>
    <h3>快来刮开!!!</h3>
    <div class="content" >中奖啦~!</div>
    <canvas id="cover" class="cover" width="400" height="400"></canvas>
    </body>

    <script>
    var isdown = false,
    cover = document.getElementById("cover"),

    covercanvas = cover.getContext("2d");
    //
    covercanvas.fillStyle="transparent";
    covercanvas.fillRect(0,0,400,400);

    function fillter( canvas ){
    canvas.fillStyle="#ccc";
    canvas.fillRect(0,0,400,400);
    }
    function isDown(e){
    e.preventDefault();
    isdown=true;
    }
    function isUp(e){
    isdown=false;
    }
    function draw( e ){
    e.preventDefault();
    if(isdown){
    if(e.changedTouches){
    e=e.changedTouches[e.changedTouches.length-1];
    }

    var _height= parseInt((window.innerHeight-400)/2),
    _width= parseInt((window.innerWidth-400)/2),
    touchTop=e.clientY - _height,
    touchLeft=e.clientX - _width;

    with(covercanvas){
    beginPath();
    arc(touchLeft, touchTop, 10, 0, Math.PI * 2);
    fill();
    }
    }
    //alert(touchTop);
    }
    fillter(covercanvas);
    covercanvas.globalCompositeOperation = 'destination-out';
    cover.addEventListener('touchstart',isDown);
    cover.addEventListener('touchmove',draw);
    cover.addEventListener('touchend',isUp);
    cover.addEventListener('mousemove',draw);
    cover.addEventListener('mousedown',isDown);
    cover.addEventListener('mouseup',isUp);

    </script>
    </html>

  • 相关阅读:
    CSS3盒模型display初探(display:box/display:flex)
    css伪元素研究(::before/::after)
    css后代选择器(div.class中间不带空格)
    css选择器(选择<div>内所有<p>元素)
    text-indent无效解决方案
    控制div位于最上层
    gulp用途
    Webpack打包工具实时更新操作(启用观察者模式)
    CLR/.NET/C#/Visual Studio/ASP.NET各版本之间的关系(转)
    前端打包/自动化构建工具:fis3
  • 原文地址:https://www.cnblogs.com/liuwenbohhh/p/4342360.html
Copyright © 2011-2022 走看看