{"id":413,"date":"2015-03-18T14:25:03","date_gmt":"2015-03-18T14:25:03","guid":{"rendered":"0deb1c54814305ca9ad266f53bc82511"},"modified":"2015-03-18T14:25:03","modified_gmt":"2015-03-18T14:25:03","slug":"","status":"publish","type":"post","link":"https:\/\/www.xiaobo.li\/notes\/archives\/413","title":{"rendered":"mobile viewport meta media"},"content":{"rendered":"<pre class=\"brush:html; toolbar: true; auto-links: true;\">&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes\" \/&gt;&nbsp; &nbsp;<\/pre>\n<p><span style=\"font-family:'Courier New';\">\u5728\u7f51\u9875\u7684&lt;head&gt;\u4e2d\u589e\u52a0\u4ee5\u4e0a\u8fd9\u53e5\u8bdd\uff0c\u53ef\u4ee5\u8ba9\u7f51\u9875\u7684\u5bbd\u5ea6\u81ea\u52a8\u9002\u5e94\u624b\u673a\u5c4f\u5e55\u7684\u5bbd\u5ea6\u3002<br \/>\n\u5176\u4e2d\uff1a<br \/>\nwidth=device-width \uff1a\u8868\u793a\u5bbd\u5ea6\u662f\u8bbe\u5907\u5c4f\u5e55\u7684\u5bbd\u5ea6<br \/>\ninitial-scale=1.0\uff1a\u8868\u793a\u521d\u59cb\u7684\u7f29\u653e\u6bd4\u4f8b<br \/>\nminimum-scale=0.5\uff1a\u8868\u793a\u6700\u5c0f\u7684\u7f29\u653e\u6bd4\u4f8b<br \/>\nmaximum-scale=2.0\uff1a\u8868\u793a\u6700\u5927\u7684\u7f29\u653e\u6bd4\u4f8b<br \/>\nuser-scalable=yes\uff1a\u8868\u793a\u7528\u6237\u662f\u5426\u53ef\u4ee5\u8c03\u6574\u7f29\u653e\u6bd4\u4f8b<br \/>\n&nbsp;<br \/>\n\u5982\u679c\u662f\u60f3\u8981\u4e00\u6253\u5f00\u7f51\u9875\uff0c\u5219\u81ea\u52a8\u4ee5\u539f\u59cb\u6bd4\u4f8b\u663e\u793a\uff0c\u5e76\u4e14\u4e0d\u5141\u8bb8\u7528\u6237\u4fee\u6539\u7684\u8bdd\uff0c\u5219\u662f\uff1a <\/span><\/p>\n<p><span style=\"font-family:'Courier New';\"><\/p>\n<pre class=\"brush:html; toolbar: true; auto-links: true;\">&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\" \/&gt;  <\/pre>\n<p><\/span><span style=\"font-family:'Courier New';\"><span style=\"white-space:normal;word-spacing:0px;text-transform:none;float:none;color:#000000;text-align:left;font:14px\/26px Arial;display:inline !important;letter-spacing:normal;background-color:#ffffff;text-indent:0px;-webkit-text-stroke-width:0px;\">\u8fd9\u6837\u5b50\u5199\u540e\uff0c\u5c31\u53ef\u4ee5\u628a\u4e00\u4e9b\u9875\u5934\u6a2a\u5e45\u7b49\u7684\u56fe\u7247\u7684\u5bbd\u5ea6\u90fd\u8bbe\u7f6e\u6210style=\"width:100%\"\uff0c\u6574\u4e2a\u9875\u9762\u5728\u8bbe\u5907\u4e0a\u770b\u8d77\u6765\u5c31\u662f\u5168\u5c4f\u7684\u4e86\u3002<\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family:'Courier New';\"><span style=\"white-space:normal;word-spacing:0px;text-transform:none;float:none;color:#000000;text-align:left;font:14px\/26px Arial;display:inline !important;letter-spacing:normal;background-color:#ffffff;text-indent:0px;-webkit-text-stroke-width:0px;\"><strong>\u8bbe\u7f6emeta<br \/>\n<\/strong>mobile\u9ed8\u8ba4\u4f1a\u50cfPC\u4e0a\u7684\u6d4f\u89c8\u5668\u4e00\u6837\u6e32\u67d3\u9875\u9762\uff08\u9ed8\u8ba4\u7684\u9875\u9762\u5bbd\u5ea6\u662f980px\uff0c\u8fd9\u4e2a\u503c\u662f\u53ef\u4ee5\u901a\u8fc7viewport\u7684width\u5c5e\u6027\u8bbe\u7f6e\u7684\uff09\uff0c\u7136\u540e\u540c\u6bd4\u7f29\u653e\u4ee5\u9002\u5e94mobile\u7684\u5c0f\u5c4f\u5e55\uff08\u7f29\u653e\u6bd4\u4f8b\u53ef\u4ee5\u901a\u8fc7minimum-scale\u548cmaxmum-scale\u8fdb\u884c\u8bbe\u5b9a\uff09\uff0c\u56e0\u6b64\u7528\u6237\u5728mobile\u770b\u8fd9\u4e2a\u9875\u9762\u65f6\u611f\u89c9\u5b57\u4f53\u5c31\u6bd4\u8f83\u5c0f\u4e86\uff0c\u4e5f\u6bd4\u8f83\u6a21\u7cca\uff0c\u5fc5\u987b\u8981\u653e\u5927\u624d\u80fd\u770b\u5f97\u771f\u5207\u3002\u4f46\u662f\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6eviewport\u6765\u89e3\u51b3\uff0cviewport\u6709\u5982\u4e0b\u51e0\u4e2a\u5c5e\u6027:<br \/>\nwidth\u8bbe\u7f6eviewport\u7684\u5bbd\u5ea6\uff0c\u5373mobile\u6700\u521d\u6a21\u62dfPC\u6d4f\u89c8\u5668\u7684\u5bbd\u5ea6\uff0c\u4e4b\u540emobile\u4f1a\u8fd9\u4e2a\u5bbd\u5ea6\u5c55\u73b0\u7684\u9875\u9762\u540c\u6bd4\u7f29\u653e\u5230mobile\u5c4f\u5e55\u4e0a\u3002\u8bbe\u7f6ewidth=device-width\u540e\u5c31\u4e0d\u4f1a\u518d\u8fdb\u884c\u7f29\u653e\u4e86\uff0c\u56e0\u4e3a\u5bbd\u5ea6\u6b63\u597d\u548cmobile\u7684\u5bbd\u5ea6\u76f8\u540c\uff08\u524d\u63d0\u662f\u6ca1\u6709\u8bbe\u7f6e\u7f29\u653e\u6bd4\u4f8b\uff09\u3002 <br \/>\nminimum-scale\u548cmaximum-scale\u662f\u63a7\u5236\u7528\u6237\u5141\u8bb8\u8bbe\u7f6e\u7684\u7f29\u653e\u6bd4\u4f8b\u7684\u3002<br \/>\n<\/span><\/span><span style=\"font-family:'Courier New';\"><span style=\"white-space:normal;word-spacing:0px;text-transform:none;float:none;color:#000000;text-align:left;font:14px\/26px Arial;display:inline !important;letter-spacing:normal;background-color:#ffffff;text-indent:0px;-webkit-text-stroke-width:0px;\">user-scalable\u6807\u8bc6\u662f\u5426\u5141\u8bb8\u5bf9\u9875\u9762\u8fdb\u884c\u7f29\u653e\uff0c\u53d6\u503c\u6709\u4e24\u4e2ayes\u548cno\u3002\u8bbe\u7f6e\u4e3ano\u5219\u4e0d\u5141\u8bb8\u8fdb\u884c\u9875\u9762\u7f29\u653e\u4e86\u3002<br \/>\ninitial-scale\u8bbe\u7f6e \u7528\u6237\u6700\u521d\u770b\u5230\u9875\u9762\u65f6\u7684\u7f29\u653e\u6bd4\u4f8b\u3002 \u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u5728html\u9875\u9762\u8bbe\u7f6e\u597d\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7JavaScript\u6765\u8bbe\u7f6e\uff0cTangram Mobile\u5b9e\u73b0\u4e86\u76f8\u5e94\u7684\u8bbe\u7f6e\u65b9\u6cd5\uff0c<br \/>\nbaidu.page.setNoScale \u8bbe\u7f6e\u9875\u9762\u9ed8\u8ba4\u4e0d\u7f29\u653e\uff0c\u5e76\u4e14\u4e0d\u53ef\u7f29\u653e<br \/>\n<strong>\u8bbe\u7f6emedia<\/strong><br \/>\n\u6211\u4eec\u53ef\u4ee5\u5229\u7528link\u6807\u7b7e\u7684media\u5c5e\u6027\u6765\u9650\u5236CSS\u7684\u5e94\u7528\u8303\u56f4\uff0c\u901a\u8fc7max-device-width\uff1a480px \u5c4f\u853dPC\uff1b\u901a\u8fc7only screen\u5c4f\u853d\u5c4f\u5e55\u9605\u8bfb\u8bbe\u5907\uff1b \u901a\u8fc7orientation: portrait\u6765\u533a\u5206\u6a2a\u5c4f\u7ad6\u5c4f\uff0c<br \/>\n@media all and (min-width:500px) { \u2026 } <br \/>\n<\/span><\/span><span style=\"font-family:'Courier New';\"><span style=\"white-space:normal;word-spacing:0px;text-transform:none;float:none;color:#000000;text-align:left;font:14px\/26px Arial;display:inline !important;letter-spacing:normal;background-color:#ffffff;text-indent:0px;-webkit-text-stroke-width:0px;\">@media (min-width:500px) { \u2026 } <br \/>\n@media (orientation: portrait) { \u2026 } <br \/>\n@media all and (orientation: portrait) { \u2026 } <br \/>\n@media screen and (min-width: 400px) and (max-width: 700px) { \u2026 }<\/span><\/span><\/p>\n<p><span style=\"font-family:'Courier New';\"><strong>\u8bbe\u5907\u7ffb\u8f6c\u72b6\u6001<\/strong><br \/>\n\u901a\u8fc7\u83b7\u53d6orientation\u7684\u503c\u6765\u5224\u65ad\u7ffb\u8f6c\u72b6\u6001\uff0c\u90a3\u5982\u679c\u8bbe\u5907\u4e0d\u652f\u6301orientation\u600e\u4e48\u6837\uff0c\u90a3\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 innerWidth\u548cinnerHeight\u7684\u6bd4\u4f8b\u6765\u5224\u65ad\u7ffb\u8f6c\u72b6\u6001\uff0c\u4ee3\u7801\u5982\u4e0b\uff08\u53d6\u81eaTangram Mobile\u7684getOrientation\uff09:\n<\/p>\n<pre class=\"brush:js; toolbar: true; auto-links: true;\">baidu.page.getOrientation = function() { \r\n    if (\"onorientationchange\" in window) { \r\n        return (window.orientation == 0 || window.orientation == 180) ? 'portrait' : 'landscape'; \r\n    } else { \r\n        return (windows.innerHeight &gt; windows.innerWidth) ? 'portrait' : 'landscape'; \r\n    } \r\n};<\/pre>\n<p><\/span> <\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family:'Courier New';\">&nbsp;<\/p>\n<p><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<pre class=\"brush:html; toolbar: true; auto-links: true;\">&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes\" \/&gt;&nbsp; &nbsp;<\/pre>\n<p><span style=\"font-family:'Courier New';\">\u5728\u7f51\u9875\u7684&lt;head&gt;\u4e2d\u589e\u52a0\u4ee5\u4e0a\u8fd9\u53e5\u8bdd\uff0c\u53ef\u4ee5\u8ba9\u7f51\u9875\u7684\u5bbd\u5ea6\u81ea\u52a8\u9002\u5e94\u624b\u673a\u5c4f\u5e55\u7684\u5bbd\u5ea6\u3002<br \/>\n\u5176\u4e2d\uff1a<br \/>\nwidth=device-width \uff1a\u8868\u793a\u5bbd\u5ea6\u662f\u8bbe\u5907\u5c4f\u5e55\u7684\u5bbd\u5ea6<br \/>\ninitial-scale=1.0\uff1a\u8868\u793a\u521d\u59cb\u7684\u7f29\u653e\u6bd4\u4f8b<br \/>\nminimum-scale=0.5\uff1a\u8868\u793a\u6700\u5c0f\u7684\u7f29\u653e\u6bd4\u4f8b<br \/>\nmaxi...<\/span><\/p>\n<p><span style=\"font-family:'Courier New';\"><\/p>\n<p><\/span><\/p>\n<p><span style=\"font-family:'Courier New';\"><\/p>\n<p><\/span><\/p>\n<p><span style=\"font-family:'Courier New';\"><\/p>\n<p><\/span> <a href=\"https:\/\/www.xiaobo.li\/notes\/archives\/413\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[283],"tags":[200],"class_list":["post-413","post","type-post","status-publish","format-standard","hentry","category-technologys","tag-viewport"],"_links":{"self":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/comments?post=413"}],"version-history":[{"count":0,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/413\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/media?parent=413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/categories?post=413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/tags?post=413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}