Window.devicePixelRatio
This read-only property returns the ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device. 
该值为分辨率之间的比,不是直接比较像素。分辨率是指单位英寸内像素数,类似于PPI。
pc端浏览器中dpr的值都为1,所以css中1px的元素在屏幕中占据1物理像素。
但在手机端,因为高分屏的出现,物理像素和css逻辑像素并不是1比1的关系。比如iPhone5中的dpr为2,就是2个物理像素对应1个逻辑像素。
另外缩放也会改变这种对应关系。

viewport

The width of the <html> element is
restricted by the width of the viewport. The <html> element takes 100% of
the width of that viewport.The viewport, in turn, is exactly equal to the
browser window: it’s been defined as such.(html的宽度由viewport的宽度决定)

document.documentElement.clientWidth,gives the dimensions
of the viewport, and not of the <html> element。 获取浏览器可视窗口的宽度(如果有滚动条时,不含滚动条的宽度)。

screen.width:屏幕的尺寸大小。You’re not interested in the physical size of
the screen, but in how many CSS pixels currently fit on it.

Media queries:针对不同尺寸的元素使用不同的样式。

Web developers are not interested in the device
width; it’s the width of the browser window that counts.So use width and forget
device-width — on desktop.

手机端

Mobile browser vendors want to offer their
clients the best possible experience, which right now means “as much like
desktop as possible.” That,
however, requires viewport to be split into two: the visual viewport and the
layout viewport. (为了能在移动设备上正常显示pc浏览器上的网站内容,引进了虚拟的layout viewport的概念。)

The visual viewport is the
part of the page that’s currently shown on-screen. The user may scroll to change
the part of the page he sees, or zoom to change the size of the visual
viewport.

How wide is the layout viewport? That differs
per browser. Safari iPhone uses 980px, Opera 850px, Android WebKit 800px, and
IE 974px. 所以pc页面的内容也能在手机上浏览,只是会缩的很小。

You can change the orientation of the frame(visual viewport), but the size and
shape of the large image (layout viewport) never changes.

Zooming

Many mobile browsers initially show any page in
fully zoomed-out mode. Most browsers zoom out to show the entire layout
viewport on the screen. browsers have chosen their dimensions of the layout
viewport such that it completely covers the screen in fully zoomed-out mode
(and is thus equal to the visual viewport). Thus the width and the height of
the layout viewport are equal to whatever can be shown on the screen in the
maximally zoomed-out mode. When the user zooms in these dimensions stay the
same.

Measuring the visual viewport

visual viewport, it is measured by window.innerWidth/Height,it shows how many CSS pixels currently fit on the screen.
Obviously the measurements change when the user zooms out or in, since more or
fewer CSS pixels fit into the screen.

Event coordinates

pageX/Y is still relative to the page in CSS pixels.

screenX/Y is relative to the screen in device pixels,
this is the same reference that clientX/Y uses, and device pixels are useless.

Meta viewport

<meta
name="viewport" content="width=320">

It is meant to resize the layout viewport. 因为移动端默认的layout
viewport比visual
viewport大,所以通过meta标签控制layout
viewport的属性达到更好的显示效果。

当设置width=device-width时,layout viewport就和visual viewport一样宽,但是屏幕会缩放到一定比率以显示所有内容。

缩放(zoom)和移动操作控制的是visual
viewport;

layout
viewport一旦初始化好后,就不会再变;可以通过meta标签的属性控制layout
viewport。

苹果6的显示效果(通过chrome测试时自动刷新常有问题,最好点击Toggle
device toolbar查看)

苹果6的dpr为2,物理分辨率为1334*750,所以visual viewport内宽可以显示375个css像素。

没有设置meta时,safari默认的layout viewport为980px,若页面的宽度小于layout
viewport的宽度,则显示980px。否则safari会不断缩小(zoom out)页面直到全部layout viewport在visual point中显示为止。

如果设置width而设定initail-scale的话,会缩放到合适比例,没有滚动条。

如果再设置initial-scale=1.0,则不会进行缩放,会产生滚动条,通过移动来显示全部内容:如下

摘自A tale of two viewports,对相关概念介绍的非常清楚。

手机端的viewport属性的更多相关文章

  1. fullpage 单屏高度超过屏幕高度,实现单屏内可以滚动并解决手机端单屏高度不正确的问题

    最近接触了好几次jquery.fullpage.js这个插件,实现整屏的滑动,效果很炫,用fullpage来实现也很简单,但是也碰到了一些问题和大家分享一下 1.单屏高度超过屏幕高度,实现单屏的滑动 ...

  2. 涨姿势!手机端的META你知道多少?

    一.天猫 <title>天猫触屏版</title> <meta content="text/html; charset=utf-8" http-equ ...

  3. 手机端的META你有多了解?

    我们先来简单了解下meta标签:meta指元素可提供有关页面的元信息(meta-information),比如针对搜索引擎和更新频度的描述和关键词. 标签位于文档的头部,不包含任何内容. 标签的属性定 ...

  4. 第九十三节,html5+css3移动手机端流体布局,基础CSS,头部设计,轮播设计,底部设计

    html5+css3移动手机端流体布局,基础CSS,头部设计,轮播设计,底部设计 基础CSS 首先将通用css属性写好 @charset "utf-8"; /*通用样式*/ /*去 ...

  5. 手机端的META你知道多少?

    一.天猫 <title>天猫触屏版</title> <meta content="text/html; charset=utf-8" http-equ ...

  6. 学习手机端的META差异,打造自己的移动网页

    我们先来简单了解下meta标签:meta指元素可提供有关页面的元信息(meta-information),比如针对搜索引擎和更新频度的描述和关键词. 标签位于文档的头部,不包含任何内容. 标签的属性定 ...

  7. 山西大同大学教务处学生端--送给学弟,学妹的礼物,可在PC端,手机端操作

    解决问题:大同大学教务处官网学生端口一进去就卡住了,点上面一行的菜单无响应 转眼已是四年,想想自己大学即将结束,不由得让人感慨啊.这才刚开学几天,我就听到有同学在因为补考,选课的事情发愁.学校官方的教 ...

  8. 手机端的META你知道多少

    一.天猫 <title>天猫触屏版</title> <meta content="text/html; charset=utf-8" http-equ ...

  9. 手机端的META

    一.天猫 <title>天猫触屏版</title> <meta content="text/html; charset=utf-8" http-equ ...

随机推荐

  1. js在(FF)中长字段溢出(自动换行)

    function toBreakWord(el,intLen){    var obj=document.getElementByIdx_x(el);     var strContent=obj.i ...

  2. table切换

    // 自己加载正确路径的jQ <!doctype html> <html><head><meta charset="utf-8">& ...

  3. Ubuntu 12.4 server 安装 redmine

    1,安装默认的redmine apt-get install apache2 libapache2-mod-passenger mysql-server redmine redmine-mysql 直 ...

  4. Python os与sys模块解析

    os与sys模块的官方解释如下: os: This module provides a portable way of using operating system dependent functio ...

  5. Intellij Idea 用Maven 创建Hibernate 项目

    第一步:创建maven项目 2. 3. 4.第三步保存之后进行下一步 到此点击finish maven项目创建成功,点击完成后会进行一系列jar包的下载 maven 仓库的默认存储位置 第二步:连接数 ...

  6. Golang分布式爬虫:抓取煎蛋文章|Redis/Mysql|56,961 篇文章

    --- layout: post title: "Golang分布式爬虫:抓取煎蛋文章" date: 2017-04-15 author: hunterhug categories ...

  7. Java容器的各种总结

    Java容器指的是List,Set,Map这些类.由于翻译的问题,问到集合,Collection这些指的都是它们几个. List ArrayList 随机访问快 LinkedList 插入删除快 这个 ...

  8. ABPZero中的Name和SurName处理

    使用ABPzero的朋友们都知道,User表中有Name和Surname两个字段,这两个字段对于国内的用户来说相当的不友好. 我们在尝试了很多的方法之后,发现无法完美将他们干掉. 所以尝试使用了一个比 ...

  9. 对Qt下对话服务器客户端的总结(MyTcpServer与MyTcpClient)

    在汇文培训老师给讲了这个例子.讲的挺好的 Qt编写聊天服务器与客户端主要用到下面两个类: QTcpSocket --- 处理连接的 QTcpServer --- 处理服务器,对接入进行响应,创建每个链 ...

  10. git的使用及常用命令

    一,GIT是什么? git是目前世界上最先进的分布式版本控制系统 Git是分布式版本控制系统,那么它就没有中央服务器的,每个人的电脑就是一个完整的版本库,这样,工作的时候就不需要联网了,因为版本都是在 ...