html5开发之viewport使用

Home » CSS » Html » 前端开发 » 移动端开发 » html5开发之viewport使用

文章归档

文件夹

转自:http://www.php100.com/html/webkaifa/HTML5/2012/0831/10979.html

结合坑爹的viewport一起了解

随着高端手机(Andriod,Iphone,Ipod,WinPhone等)的盛行,移动互联应用开发也越来越受到人们的重视,用html5开发移动应用是最好的选择。然而,每一款手机有不同的分辨率,不同屏幕大小,如何使我们开发出来的应用或页面大小能适合各种高端手机使用呢?学习html5
viewport的使用能帮你做到这一点……viewport 语法介绍:

01<!– html document –>
02<meta name=”viewport”
03content=”
04height = [pixel_value | device-height]
,
05width = [pixel_value | device-width ]
,
06initial-scale = float_value ,
07minimum-scale = float_value ,
08maximum-scale = float_value ,
09user-scalable = [yes | no] ,
10target-densitydpi = [dpi_value | device-dpi | high-dpi | medium-dpi
| low-dpi]
11″
12/>

width

控制 viewport 的大小,可以指定的一个值或者特殊的值,如 device-width 为设备的宽度(单位为缩放为 100% 时的 CSS
的像素)。

height

和 width 相对应,指定高度。

target-densitydpi

一个屏幕像素密度是由屏幕分辨率决定的,通常定义为每英寸点的数量(dpi)。Android支持三种屏幕像素密度:低像素密度,中像素密度,高像素密度。一个低像素密度的屏幕每英寸上的像素点更少,而一个高像素密度的屏幕每英寸上的像素点更多。Android
Browser和WebView默认屏幕为中像素密度。

下面是 target-densitydpi 属性的 取值范围

  • device-dpi –使用设备原本的 dpi 作为目标 dp。 不会发生默认缩放。
  • high-dpi – 使用hdpi 作为目标 dpi。 中等像素密度和低像素密度设备相应缩小。
  • medium-dpi – 使用mdpi作为目标 dpi。 高像素密度设备相应放大, 像素密度设备相应缩小。 这是默认的target density.
  • low-dpi -使用mdpi作为目标 dpi。中等像素密度和高像素密度设备相应放大。
  • <value> – 指定一个具体的dpi 值作为target dpi. 这个值的范围必须在70–400之间。
1<!– html document –>
2<meta name=”viewport” content=”target-densitydpi=device-dpi” />
3<meta name=”viewport” content=”target-densitydpi=high-dpi” />
4<meta name=”viewport” content=”target-densitydpi=medium-dpi” />
5<meta name=”viewport” content=”target-densitydpi=low-dpi” />
6<meta name=”viewport” content=”target-densitydpi=200″ />

为了防止Android Browser和WebView
根据不同屏幕的像素密度对你的页面进行缩放,你可以将viewport的target-densitydpi 设置为
device-dpi。当你这么做了,页面将不会缩放。相反,页面会根据当前屏幕的像素密度进行展示。在这种情形下,你还需要将viewport的width定义为与设备的width匹配,这样你的页面就可以和屏幕相适应。

initial-scale

初始缩放。即页面初始缩放程度。这是一个浮点值,是页面大小的一个乘数。例如,如果你设置初始缩放为“1.0”,那么,web页面在展现的时候就会以target
density分辨率的1:1来展现。如果你设置为“2.0”,那么这个页面就会放大为2倍。

maximum-scale

最大缩放。即允许的最大缩放程度。这也是一个浮点值,用以指出页面大小与屏幕大小相比的最大乘数。例如,如果你将这个值设置为“2.0”,那么这个页面与target
size相比,最多能放大2倍。

user-scalable

用户调整缩放。即用户是否能改变页面缩放程度。如果设置为yes则是允许用户对其进行改变,反之为no。默认值是yes。如果你将其设置为no,那么minimum-scale
和 maximum-scale都将被忽略,因为根本不可能缩放。

所有的缩放值都必须在0.01–10的范围之内。

例:

(设置屏幕宽度为设备宽度,禁止用户手动调整缩放)

<meta name=”viewport” content=”width=device-width,user-scalable=no”
/>

(设置屏幕密度为高频,中频,低频自动缩放,禁止用户手动调整缩放)

<meta name=”viewport”
content=”width=device-width,target-densitydpi=high-dpi,initial-scale=1.0,
minimum-scale=1.0, maximum-scale=1.0, user-scalable=no”/>

16 Responses to “html5开发之viewport使用”
  • huaraches

    I am commenting to let you know of the notable discovery my friend’s daughter gained viewing your blog. She learned a lot of things, including what it is like to possess a wonderful coaching character to make certain people clearly comprehend some very confusing matters. You actually surpassed her expected results. Thank you for displaying such priceless, trustworthy, informative and also easy guidance on the topic to Tanya.

    回复
  • adidas ultra boost

    I am also commenting to make you know of the notable encounter my daughter obtained browsing your blog. She even learned many things, which include what it is like to have an ideal helping mood to let the others without problems fully grasp a number of grueling things. You actually did more than visitors’ expected results. Thank you for showing these insightful, trustworthy, revealing and even fun thoughts on your topic to Sandra.

    回复
  • yeezy boost 350

    My husband and i ended up being now thrilled Chris managed to deal with his investigations by way of the ideas he got when using the site. It is now and again perplexing to just always be giving out solutions which most people have been making money from. And we fully grasp we’ve got the blog owner to appreciate for this. Those explanations you’ve made, the easy web site navigation, the relationships you will assist to instill – it is many impressive, and it is letting our son and the family do think the matter is amusing, which is certainly very fundamental. Many thanks for all!

    回复
  • golden goose

    I intended to write you one little bit of observation just to say thanks a lot over again with your incredible tips you have shared on this website. This is quite open-handed of you to make easily what many individuals might have sold for an ebook to end up making some bucks for their own end, notably considering that you could possibly have tried it in case you considered necessary. Those suggestions likewise worked to be the great way to comprehend someone else have similar interest the same as mine to know the truth much more when considering this problem. I am sure there are many more pleasurable periods in the future for those who look over your site.

    回复
  • adidas tubular x

    Thanks a lot for providing individuals with remarkably pleasant opportunity to discover important secrets from here. It is always so amazing plus stuffed with a good time for me personally and my office fellow workers to visit your website at a minimum thrice per week to learn the new items you have got. And lastly, I’m just usually fulfilled with the effective ideas served by you. Selected 2 tips in this post are surely the most impressive I’ve ever had.

    回复
  • moncler sale

    My spouse and i were quite fulfilled when Raymond could do his basic research through the entire precious recommendations he received in your web page. It’s not at all simplistic to simply find yourself offering information men and women have been selling. And we also take into account we now have the website owner to be grateful to because of that. The main illustrations you have made, the simple web site menu, the relationships you help create – it’s got mostly terrific, and it’s aiding our son and us consider that the content is brilliant, and that’s seriously vital. Many thanks for everything!

    回复
  • golden goose outlet

    I needed to put you the little word to help say thanks a lot as before for those marvelous methods you’ve featured at this time. It is certainly seriously generous of you to supply easily all many people would’ve marketed for an ebook to get some cash on their own, precisely now that you might have done it if you wanted. These principles additionally served as a easy way to be certain that other people have a similar interest just as my personal own to figure out good deal more in terms of this issue. I am sure there are several more pleasant occasions up front for people who read your blog post.

    回复
  • nike flyknit racer

    I want to get across my appreciation for your kindness supporting those individuals that require guidance on your topic. Your real commitment to passing the message all through had been surprisingly informative and have continuously empowered men and women like me to achieve their endeavors. The helpful suggestions indicates a lot to me and a whole lot more to my office colleagues. With thanks; from everyone of us.

    回复
  • kate spade handbags

    I needed to write you a bit of word to help say thanks over again with the lovely pointers you’ve featured at this time. It’s so pretty open-handed with you to allow easily exactly what some people could possibly have marketed as an e-book to get some money on their own, even more so since you could possibly have done it if you ever wanted. Those creative ideas also worked to provide a easy way to fully grasp that the rest have the same keenness just like my personal own to figure out significantly more in respect of this problem. I believe there are millions of more pleasant opportunities ahead for many who discover your site.

    回复
  • adidas nmd

    I precisely wanted to thank you very much again. I am not sure the things I could possibly have accomplished in the absence of the entire aspects discussed by you over my industry. Previously it was a daunting condition in my opinion, however , encountering the very well-written approach you solved that forced me to leap over fulfillment. I am grateful for your work and in addition believe you know what a powerful job you happen to be doing teaching many people thru your websites. I know that you have never come across all of us.

    回复
  • timberland outlet

    I have to get across my appreciation for your generosity giving support to folks that have the need for assistance with this concept. Your real commitment to passing the message along had become really advantageous and have specifically allowed guys like me to achieve their pursuits. Your own invaluable advice implies a great deal to me and extremely more to my peers. Best wishes; from each one of us.

    回复
  • adidas ultra boost

    My spouse and i were quite thankful when Michael managed to do his investigations through the entire ideas he received out of the web pages. It’s not at all simplistic to simply choose to be giving freely tips which often men and women could have been trying to sell. And we all fully grasp we have got you to appreciate because of that. The specific illustrations you made, the easy blog navigation, the relationships you can give support to promote – it is many fantastic, and it’s making our son and our family believe that that issue is thrilling, and that’s especially serious. Thank you for all the pieces!

    回复
  • kobe byrant shoes

    Thanks for all your efforts on this web page. My mother enjoys going through investigation and it’s simple to grasp why. We hear all relating to the powerful tactic you make great strategies by means of this web blog and as well as invigorate participation from website visitors about this situation while our own princess is in fact starting to learn a lot of things. Have fun with the rest of the year. Your conducting a stunning job.

    回复
  • foamposites

    I wanted to post you a little word to give thanks the moment again for your spectacular advice you have documented in this case. It was seriously open-handed of you to give easily all many people could possibly have distributed for an e-book to get some money for themselves, even more so considering the fact that you could possibly have tried it in the event you desired. The secrets additionally served as a easy way to be sure that other people online have similar dream much like my own to see a lot more on the topic of this issue. I think there are millions of more pleasant occasions up front for individuals who looked at your site.

    回复
  • ultra boost

    I wish to express thanks to you just for rescuing me from this type of problem. Just after looking out throughout the search engines and getting strategies which are not beneficial, I believed my life was well over. Existing without the strategies to the issues you have fixed all through your entire short article is a critical case, as well as those that could have in a negative way affected my career if I had not come across your site. Your mastery and kindness in touching all things was very useful. I am not sure what I would have done if I had not encountered such a step like this. I can also at this time relish my future. Thank you very much for your skilled and result oriented guide. I will not think twice to endorse your blog to anyone who desires tips on this topic.

    回复
  • nmd

    I’m commenting to let you know what a amazing encounter our child gained browsing your site. She noticed too many details, not to mention what it’s like to possess a marvelous giving heart to let other folks without difficulty master selected hard to do topics. You really exceeded our own desires. Thank you for distributing these practical, dependable, revealing and as well as easy tips about that topic to Emily.

    回复

发表评论

Your email address will not be published.