Table of Contents
回复内容:
Home Web Front-end H5 Tutorial 腾讯问卷 http://ur.qq.com/ 是如何实现导航栏毛玻璃背景效果的?

腾讯问卷 http://ur.qq.com/ 是如何实现导航栏毛玻璃背景效果的?

Jun 07, 2016 am 08:42 AM
canvas com html http

腾讯问卷 ur.qq.com/ 看上去似乎通过以下方式实现了导航栏毛玻璃背景效果:

  • html2canvas - html2canvas.hertzen.com
  • StackBlur - quasimondo.com/StackBlu
  • HTML 5 Canvas
但是自己在本地试了试发现弄不出完美的效果,不知道具体是怎么实现的。
另外参见 fsasso.com/labs/blur/ 居然也很容易地实现了 CSS 3 + HTML 5 丝般顺滑的导航栏毛玻璃背景效果。

截图:

回复内容:

canvas截了一张大图,滤镜处理(毛玻璃化),放在了header容器后面,尺寸与header容器一致,且header容器设置半透,漏出后面的截图。
该canvas元素垂直坐标与浏览器滚动同步,保证漏出的区域是页面的背景。
原理很简单,有些效果细节花了点心思调节。

1.截图的时候,header先隐藏,否则最顶部的效果出不来。
2.当浏览器resize的时候,需要重新截图。这里处理暴力了点,直接删掉滤镜层,避免重复截图的性能消耗。感兴趣的,可以做一下函数节流来提升resize时候重新截图的性能。
3.根据最近WWDC,safari支持原生毛玻璃效果。caniuse.com/#

话说我们改域名了,wj.qq.com/ 实现这个毛玻璃的效果需要用到的库和方法楼主基本都提到了。
具体实现过程可以参考 @黎博 的答案
补充一些实现过程中的细节
  1. html2canvas效率很低,如果页面中的dom较多,渲染时间可达300ms+,所以实时渲染是做不到的。所以只能在初始化的时候截一个长图,然后通过移动图片的位置来实现。
  2. resize的时候要放弃之前的图,是因为很多元素的排版在重绘的时候的相对位置会发生改变,因此原先的图可能无法复用。(可以在lz举得这个例子Blur!中尝试resize下就能看到副作用)
  3. html2canvas是根据dom树和css样式绘制canvas的,所以如果有动画或者存在样式变化的元素要做特殊处理
  4. 没有达到完美效果可能是楼主忽略了一个半透明的遮罩层,毛玻璃的效果只有模糊还是不够的
  5. ls说提前截图的方案在一定程度上也是可行的,但是考虑到第二个因素以及维护成本(比如换了背景图,样式修改什么的就要记得重新截一次图)可能就不是特别合适
腾讯问卷 http://ur.qq.com/ 是如何实现导航栏毛玻璃背景效果的?用了HTML5标准的rgba色,alpha通道值是0.8

腾讯问卷 http://ur.qq.com/ 是如何实现导航栏毛玻璃背景效果的?下边缘阴影

————————————————————————
腾讯问卷 http://ur.qq.com/ 是如何实现导航栏毛玻璃背景效果的?你是说这个阴影么,这就是box-shadow啊,我都给你截图了... Opera30.0下测试,窗体resize之后,毛玻璃效果丢失。 楼上分析的做法是对的
腾讯问卷 http://ur.qq.com/ 是如何实现导航栏毛玻璃背景效果的?这个模糊效果不是实时的,将按钮换个颜色就发现了。而且你看,他们的轮播图连背景也没换,其实也不需要渲染页面后截图,整张网页的图是早就截好的。

至于下面那个网址...

腾讯问卷 http://ur.qq.com/ 是如何实现导航栏毛玻璃背景效果的?这么一段代码不就已经说明一切了么。
filter: blur(20px)
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

See all articles