demo 微信毛玻璃效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>canvas catch red</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript"></script>
<link href="blur.css" rel="stylesheet" type="text/css">
<meta name="viewport"
content=" height = device-height,
width = device-width,
initial-scale = 1.0,
minimum-scale = 1.0,
maximum-scale = 1.0,
user-scalable = no"/>
</head>
<body>
<div id="blur-div">
<img id="blur-img" src="data:image.jpg">
<canvas id="canvas"></canvas>
<a id="rest-button" href="javascript:rest()" class="button">reset</a>
<a id="show-button" href="javascript:show()" class="button">show</a>
</div>
<script src="blur.js" type="text/javascript"></script>
</body>
</html>
var canvasWidth = window.innerWidth;
var canvasHeight = window.innerHeight; var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d"); canvas.width = canvasWidth;
canvas.height = canvasHeight; var image = new Image();
var radius = 50;
var clippingRegion = {x:400, y: 200, r:50};
var leftMargin = 0;
var topMargin = 0;
var timer = null;
image.src = "image.jpg"; image.onload = function (e){
$("#blur-div").css("width",canvasWidth+"px");
$("#blur-div").css("height",canvasHeight+"px"); $("#blur-img").css("width",image.width+"px");
$("#blur-img").css("height",image.height+"px"); leftMargin = (image.width - canvas.width)/2;
topMargin = (image.height - canvas.height)/2; $("#blur-image").css("top",String(-topMargin)+"px");
$("#blur-image").css("left",String(-leftMargin)+"px"); initCanvas()
} function initCanvas(){
var theLeft = leftMargin<0?-leftMargin:0;
var thetop = topMargin<0?-topMargin:0;
clippingRegion = { x: Math.random()*(canvas.width - 2*radius - 2*theLeft) + radius + theLeft,
y: Math.random()*(canvas.height - 2*radius - 2*thetop) + radius + thetop, r:radius };
draw(image, clippingRegion);
} function setClippingRegion(clippingRegion){
context.beginPath();
context.arc(clippingRegion.x, clippingRegion.y, clippingRegion.r, 0, Math.PI *2,false);
context.clip();
} function draw(image, clippingRegion){
context.clearRect(0,0,canvas.width, canvas.height); context.save();
setClippingRegion(clippingRegion);
context.drawImage( image,
Math.max(leftMargin,0),
Math.max(topMargin, 0),
Math.min(canvas.width,image.width), Math.min(canvas.height,image.height),
leftMargin<0?-leftMargin:0,
topMargin<0?-topMargin:0,
Math.min(canvas.width,image.width), Math.min(canvas.height,image.height) );
context.restore();
} function rest(){ if( timer != null ){
clearInterval(timer)
timer = null
}
initCanvas()
};
function show(){
if(timer == null){
timer = setInterval(
function (){
clippingRegion.r +=20;
if(clippingRegion.r > 2*Math.max(canvas.width,canvas.height)){
clearInterval(timer);
}
draw(image,clippingRegion);
},30); } }; canvas.addEventListener("touchstart",function(e){
e.preventDefault()
});
*{
margin:0 0;
padding:0 0;
} #blur-div{
overflow: hidden;;
margin:0 auto;
position: relative; } #blur-img{;
margin:0 auto;
display: block; filter: blur(20px);
-webkit-filter: blur(20px);
-moz-filter: blur(20px);
-ms-filter: blur(20px);
-o-filter: blur(20px); position: absolute;
top:0px;
left:0px; z-index:0 ;
} #canvas{
display: block;
margin:0 auto; position: absolute;
left: 0px;
top:0px; z-index:; } .button{
display:block;
position: absolute;
z-index:; width:100px;
height:30px; color: white;
text-decoration: none;
text-align: center;
line-height: 30px; border-radius: 5px;
cursor: pointer; } #rest-button{
left:50x;
bottom: 20px;
background-color: #058;
} #rest-button:hover{
background-color: #047;
} #show-button{
right:50px;
bottom:20px;
background-color: #085;
} #show-button:hover{
background-color: #074;
}
demo 微信毛玻璃效果的更多相关文章
- 小tip: 使用CSS将图片转换成模糊(毛玻璃)效果
去年盛夏之时,曾写过“小tip: 使用CSS将图片转换成黑白”一文,本文的模式以及内容其实走得是类似路线.CSS3 → SVG → IE filter → canvas. 前段时间,iOS7不是瓜未熟 ...
- [转] 小tip: 使用CSS将图片转换成模糊(毛玻璃)效果 ---张鑫旭
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=3804 去年盛夏之时, ...
- iOS 实现毛玻璃效果
话说苹果在iOS7.0之后,很多系统界面都使用了毛玻璃效果,增加了界面的美观性,比如下图的通知中心界面; 但是其iOS7.0的SDK并没有提供给开发者实现毛玻璃效果的API,所以很多人都是通过一些别人 ...
- CSS技巧收集——毛玻璃效果
先上 demo和 源码 其实毛玻璃的模糊效果技术上比较简单,只是用到了 css 滤镜(filter)中的 blur 属性.但是要做一个好的毛玻璃效果,需要注意很多细节. 比如我们需要将上图中页面中间的 ...
- 使用UIVisualEffectView创建毛玻璃效果
UIVisuaEffectView :继承自UIView,可以看成是专门用于处理毛玻璃效果的视图,只要我们将这个特殊的View添加到其他视图(eg. ImageView )上面,被该UIVisuaEf ...
- CSS 奇思妙想 | 全兼容的毛玻璃效果
通过本文,你能了解到 最基本的使用 CSS backdrop-filter 实现磨砂玻璃(毛玻璃)的效果 在至今不兼容 backdrop-filter 的 firefox 浏览器,如何利用一些技巧性的 ...
- 使用CSS3制作导航条和毛玻璃效果
导航条对于每一个Web前端攻城狮来说并不陌生,但是毛玻璃可能会相对陌生一些.简单的说,毛玻璃其实就是让图片或者背景使用相应的方法进行模糊处理.这种效果对用户来说是十分具有视觉冲击力的. 本次分享的主题 ...
- 解决css3毛玻璃效果(blur)有白边问题
做一个登录页,全屏背景图毛玻璃效果,实现方法如下: HTML: <body> <div class="login-wrap"> <div class= ...
- Swift 之模糊效果(毛玻璃效果,虚化效果)的实现
前言: 之前项目中有用到过Objective-C的的模糊效果,感觉很是不错,而且iOS8之后官方SDK也直接提供了可以实现毛玻璃效果的三个类:UIBlurEffect.UIVibrancyEffect ...
随机推荐
- jenkins 自定义主题
一.概述 jenkins更新后,页面css布局都已改变,我现在用的jenkins.css, ( png图片需自定义) #page-body { background-image:url(http:// ...
- Reversion windows 2008 R2 STD to Datacenter
1.To determine the installed edition, run: DISM /online /Get-CurrentEdition 2.To check the possible ...
- myeclipse maven web项目配置
启用maven:window-->preference-->MyEclipse-->Maven4MyEclipse, 勾选复选框(Enable Mave4MyEclipse feat ...
- 【Apache Nutch系列】Nutch2.0配置安装异常集锦
1.java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration Exception in thread &qu ...
- hdu 4359 dp
/* 题目大意:给n个节点的二叉树第i个节点的权值为2^(i-1), 求所有含左右子树的节点都符合左子树的权和小于右子树权和的种数. */ #include <iostream> #inc ...
- wget下载整个网站的方法
转自: http://blog.itpub.net/29867/viewspace-716088/ (修改部分内容) wget --restrict-file-name=ascii -m -c -n ...
- Couchbase应用示例(初探)
安装过程:略. 1. 新建Web项目 从NuGet获取并引用: CouchbaseNetClient,添加后引用列表显示为 : Couchbase.NetClient 2. 需要对项目添加引用,这里我 ...
- (33)C#正则表达式
正则表达式:专门用于字符串处理的语言,用来描述字符串特征的表达式 元字符 . 之间可以出现任意单个字符(除了\n 换行) 例如: a.b 意思是这个表达式必须是三个字符,第一个字符是a,第三个字符 ...
- Tarjan缩点+Spfa最长路【p3627】[APIO2009] 抢掠计划
Description Siruseri 城中的道路都是单向的.不同的道路由路口连接.按照法律的规定, 在每个路口都设立了一个 Siruseri 银行的 ATM 取款机.令人奇怪的是,Siruseri ...
- 洛谷——P1403 [AHOI2005]约数研究
P1403 [AHOI2005]约数研究 题目描述 科学家们在Samuel星球上的探险得到了丰富的能源储备,这使得空间站中大型计算机“Samuel II”的长时间运算成为了可能.由于在去年一年的辛苦工 ...