HTML5 | IT-北北报

html5刮刮卡

2015/12 09 21:12

备份个刮刮卡源码

先看个刮刮卡Demo

其实就一个canvas

<canvas width=”270″ height=”129″ style=”position: absolute; background-image: url(这里是你要刮的那个图); background-color: transparent;”>

 

剩下的交给js

(function(bodyStyle){
bodyStyle.mozUserSelect = ‘none’;
bodyStyle.webkitUserSelect = ‘none’;
var img = new Image();
var canvas = document.querySelector(‘canvas’);
canvas.style.backgroundColor=’transparent’;
canvas.style.position = ‘absolute’;
img.addEventListener(‘load’,function(e){
var ctx;
var w = img.width, h = img.height;
var offsetX = canvas.offsetLeft, offsetY = canvas.offsetTop;
var mousedown = false;
function layer(ctx){
ctx.fillStyle = ‘gray’;
ctx.fillRect(0, 0, w, h);
}
function eventDown(e){
e.preventDefault();
mousedown=true;
}
function eventUp(e){
e.preventDefault();
mousedown=false;

var data = ctx.getImageData(0,0,w,h).data;
for(var i=0,j=0;i<data.length;i+=4){
if(data[i] && data[i+1] && data[i+2] && data[i+3]){
j++;
}
}
//当图层被擦除剩余50%时触发
if(j<=w*h*0.5){
ctx.clearRect(0,0,w,h);
alert(“颤抖吧,小渣渣!”);
}
}
function eventMove(e){
e.preventDefault();
if(mousedown){
if(e.changedTouches){
e=e.changedTouches[e.changedTouches.length-1];
}
var x = (e.clientX + document.body.scrollLeft || e.pageX) – offsetX || 0,
y = (e.clientY + document.body.scrollTop || e.pageY) – offsetY || 0;
with(ctx){
beginPath()
arc(x, y, 50, 0, Math.PI * 2);
fill();
}
}
}
canvas.width=w;
canvas.height=h;
canvas.style.backgroundImage=’url(‘+img.src+’)';
ctx=canvas.getContext(’2d’);
ctx.fillStyle=’transparent’;
ctx.fillRect(0, 0, w, h);
layer(ctx);
ctx.globalCompositeOperation = ‘destination-out’;
canvas.addEventListener(‘touchstart’, eventDown);
canvas.addEventListener(‘touchend’, eventUp);
canvas.addEventListener(‘touchmove’, eventMove);
canvas.addEventListener(‘mousedown’, eventDown);
canvas.addEventListener(‘mouseup’, eventUp);
canvas.addEventListener(‘mousemove’, eventMove);
});

})(document.body.style);

html5标准样式

2015/09 30 20:09
 * {
margin: 0;
padding: 0;
outline: none;
}
*:not(input,textarea) {
-webkit-touch-callout: inherit;
-webkit-user-select: auto;
}
body {
width: 100%;
font-family: Hiragino Sans GB, Arial, Helvetica, ”黑体”, sans-serif;
font-size: 14px;
color: #878787;
-webkit-touch-callout: inherit ;
-webkit-user-select: auto ;
background-color: #fff;
}
a {
color: #878787;
text-decoration: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
a:hover {
text-decoration: none;
}
button,input,select,textarea {
font-size: 100%;
margin: 0;
padding: 0;
outline: none;
}
dt,dd {
display: inline-block;
}
textarea,input {
resize: none;
outline: none;
}
textarea {
resize: none;
-webkit-appearance: none;
}
ul,ol,li {
list-style: none;
}
em {
font-style: normal;
}

CSS3双色字

2015/05 29 14:05
css3-font

闲话少叙,直接上代码-北北

<style>
.my-font {
font: 100px/400px impact;
text-align: center;
background-image: -webkit-gradient(linear,
center top, center bottom,
from(rgba(0, 128, 0, 1)),
color-stop(0.5, rgba(0, 128, 0, 1)),
color-stop(0.5, rgba(51, 51, 51, 1)),
to(rgba(51, 51, 51, 1)));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
</style>

<body>
<div class=”my-font”>129,318,564</div>
</body>



无觅相关文章插件,快速提升流量