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 ...
随机推荐
- Oracle SQL 疑难解析读书笔记(一 基础)
1.在语句中找到和消除空值 select first_name,last_name from hr.employees where commission_pct is null is null 和 i ...
- Angular1 基础知识 浅析(含锚点)
1.angular:前端js框架 https://angularjs.org ① SPA单页应用程序 通过ajax从后台获取数据,动态渲染页面,不出现白屏,提高效率,节省流量 (1)锚点值 锚点:是 ...
- laravel 学习笔记 —— 神奇的服务容器
转载自:https://www.insp.top/learn-laravel-container 容器,字面上理解就是装东西的东西.常见的变量.对象属性等都可以算是容器.一个容器能够装什么,全部取决于 ...
- CodeForces 659D Bicycle Race (判断点是否为危险点)
D - Bicycle Race Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- [ CodeVS冲杯之路 ] P1576
不充钱,你怎么AC? 题目:http://codevs.cn/problem/1576/ 这和上一道题十分的类似,所以直接秒杀 ( 上一题:http://www.cnblogs.com/hadilo/ ...
- HTTP GET与POST区别
HTTP定义了与服务器交互的不同方法,最基本的方法是 GET 和 POST. HTTP-GET和HTTP-POST是使用HTTP的标准协议动词,用于编码和传送变量名/变量值对参数,并且使用相关的请求语 ...
- 【linux高级程序设计】(第十一章)System V进程间通信 3
信号量通信机制 可以看到,跟消息队列类似,也是包括两个结构. int semget (key_t __key, int __nsems, int __semflg) : 创建信号量集合 第一个参数:f ...
- 陕西师范大学第七届程序设计竞赛网络同步赛 C iko和她的糖【贪心/ STL-优先队列/ 从1-N每个点有能量补充,每段有消耗,选三个点剩下最多能量】
链接:https://www.nowcoder.com/acm/contest/121/C来源:牛客网 题目描述 iko超级超级喜欢吃糖,有一天iko想出去玩,她计划从1点走到N点(按1,2,3,.. ...
- UVA 437 巴比伦塔 【DAG上DP/LIS变形】
[链接]:https://cn.vjudge.net/problem/UVA-437 [题意]:给你n个立方体,让你以长宽为底,一个个搭起来(下面的立方体的长和宽必须大于上面的长和宽)求能得到的最长高 ...
- poj2406(后缀数组)
poj2406 题意 给出一个字符串,它是某个子串重复出现得到的,求子串最多出现的次数. 分析 后缀数组做的话得换上 DC3 算法. 那么子串的长度就是 \(len - height[rnk[0]]\ ...