砍敺 media 2014-12-10 19:08 蝺刻摩
, ~- B9 \0 S; ]5 I2 ^; ?& q
! b8 x5 c( A8 N/ ~6 a3 x3 l餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
3 X( Y6 T! J% V9 `+ u# f- <script type="text/javascript">
# t1 n, V2 K: V+ J" T: R: p0 @5 m - <!--
G/ z8 }* O; F' c - ; J" k( e$ E" z) P
- var viewportwidth;+ ]9 R, M( Z% n# y- \7 \1 x' C
- var viewportheight;% `/ x9 w' |4 h4 g, N# N
-
( r& X" N3 B" {. i+ ~ - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight9 q" _$ D- ?5 B3 k' r
-
( `; O0 F5 H4 t9 Q7 A - if (typeof window.innerWidth != 'undefined')2 z2 S4 U8 R+ i3 ]6 i( x) P) d
- {$ I- f1 w/ i3 ~, j& D A) w2 b# p
- viewportwidth = window.innerWidth,' Y: j9 m/ o8 D" F" v: K$ P
- viewportheight = window.innerHeight: o/ e" Z* q) _! h9 |! \& H& Y4 `
- }7 K0 X& f" B) S p
- 8 q# z0 q8 C, u, G! O+ S3 V: r" g5 b6 I
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
# z4 x6 C1 O$ d - $ P0 B6 Y' z& Z( ?. n
- else if (typeof document.documentElement != 'undefined'
! B6 \- Z. Q% z7 c - && typeof document.documentElement.clientWidth !=
4 o7 Y9 G" e0 a7 d" I - 'undefined' && document.documentElement.clientWidth != 0)
) x: k% f3 K9 } r* {8 G* Z - {
6 h& g2 Q; P( j$ _6 |* I/ T - viewportwidth = document.documentElement.clientWidth,
6 Z8 _# a2 U5 r0 l# ^! Z/ | - viewportheight = document.documentElement.clientHeight5 G3 v8 k3 S4 P' N! @) Y$ C5 S8 ^
- }
6 L% M$ }* V1 @8 a2 U - 9 J4 ]" c3 }" N$ d" G# c
- // older versions of IE
2 K" s8 D/ T2 u0 K -
) g5 Z7 M4 { T( u - else% ]8 z0 v/ b* n8 i& f
- {
1 @% S$ K4 j; f; K, f - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,, s; V7 _8 d8 U0 z% I9 Z
- viewportheight = document.getElementsByTagName('body')[0].clientHeight, m0 P8 j) X+ V V: T1 B
- }& |2 i T1 ?/ {+ \
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
% j( E( r3 K5 ]) e$ g( ~6 I( a - //-->, {' M- @9 `5 j& K" s- n
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
; m9 U! Z- O$ \7 D; _; ?
# z" }4 Q" b& w3 f8 Y4 |2 Z2 K1 C9 X1 w: j5 }$ Z' x0 @
靘皞: Get viewport size (width and height) with javascript
- x# |8 c+ Q' U1 m' [+ \$ E3 X5 q- [0 ]) i! O
) H0 d7 {7 G7 j1 h: I |
|