砍敺 media 2014-12-10 19:08 蝺刻摩
, D/ b4 E/ ?1 A' T0 i7 v5 b* {0 N' T* N
: w+ H3 y6 b V" q( [餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
0 K! C% {7 e5 ~% P6 i- <script type="text/javascript">3 `4 I/ O8 F* P9 F
- <!--
& [* T n* N- f* a' F# z
+ G9 O6 t9 X) t- var viewportwidth;
, @( d6 d& ?+ z4 k/ O - var viewportheight;% ~' {$ q2 {: t+ D" q
-
9 [5 u1 I" C6 u+ [% a% P - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight9 k+ m# u4 \7 H0 f
-
- b( D* z8 y, m/ H" u* l) y& j - if (typeof window.innerWidth != 'undefined')
4 d. g0 P$ N! U/ ^ - {
7 D5 v8 {5 j$ _ R4 M0 c+ p7 d - viewportwidth = window.innerWidth,/ u+ o# s# O3 T3 L% l
- viewportheight = window.innerHeight( r1 D* d, F" r4 a! @; j z
- }
; j0 z% T8 C1 {* V( ~ -
* @6 \0 t# ]' |; j; F* }! @ - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)0 P5 Z- h3 m* @4 _, j- O6 d
2 ^5 a3 L' ]8 G( N- else if (typeof document.documentElement != 'undefined'
3 F* s6 |/ r3 k* s; D, h2 } - && typeof document.documentElement.clientWidth !=: X0 H5 M! h/ Q" H
- 'undefined' && document.documentElement.clientWidth != 0)& w( Q" s8 A2 e |8 u
- {5 Y8 O3 |% I# h1 z
- viewportwidth = document.documentElement.clientWidth,$ j3 H3 A# {! v& q
- viewportheight = document.documentElement.clientHeight& s+ W* }& d$ T$ r
- }
, ?" a Y" p @# | -
4 l1 k7 ~# J( ]2 @% b& H4 D - // older versions of IE ~' {* Q$ S# Q# H v) R- u
- % {. j) ~* H( G" e0 l( l2 L
- else3 @( u7 \% a- s ~
- {
$ p1 F2 M- C0 F# n' @8 C' \( G - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,1 |4 n# A, r, y- k5 k5 y& G
- viewportheight = document.getElementsByTagName('body')[0].clientHeight
7 T) n( k, |4 U8 \* f P - }
2 \2 H( }, V; N7 l - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
5 `/ Q8 K2 s4 U0 x! I" j - //-->
9 I' z/ d# @; j* g) }) | - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯. @7 I7 V, l% m+ G) r8 \7 k% H
$ b- i$ t+ O0 ?1 g! {0 G% {3 E' C8 n
% w( K% f4 v1 P2 U
靘皞: Get viewport size (width and height) with javascript
3 b, s: l$ C7 \+ Z* P) [8 \7 I
; T# Z8 J9 o$ J1 M6 z& v# d5 P9 k
, c: f4 U0 c9 Y4 G+ O |
|