首页 > 代码库 > 毛玻璃背景
毛玻璃背景
div { -moz-filter: blur(5px); -webkit-filter: blur(5px); -o-filter: blur(5px); -ms-filter: blur(5px); filter: blur(5px); }
上面是css方式,以下是html5方式:
blur(document.getElementById(‘logo‘),‘http://s.segmentfault.com/img/logo.png‘,2); function blur(element, src, strength){ var image = new Image(); image.onload = function(e){ var canvas = document.createElement(‘canvas‘); var context = canvas.getContext(‘2d‘); canvas.width = this.width; canvas.height = this.height; context.drawImage(this, 0, 0); context.globalAlpha = 0.5; // Higher alpha made it more smooth // Add blur layers by strength to x and y // 2 made it a bit faster without noticeable quality loss for (var y = -strength; y <= strength; y += 2) { for (var x = -strength; x <= strength; x += 2) { context.drawImage(canvas, x, y); } } context.globalAlpha = 1; element.style.backgroundImage = ‘url(‘+canvas.toDataURL()+‘)‘; } image.src = src; }
毛玻璃背景
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。