砍敺 media 2014-12-10 19:08 蝺刻摩 8 l7 O+ y# E% l( k4 D! a h
7 T' j* u. g7 p8 @% n6 W4 G7 L) T- P' i餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
6 i: c1 u8 [- D# |- <script type="text/javascript">( S! O3 K# Y* @% ]
- <!--# C' l" ~5 Y! P$ f% p. m- a" M
- u3 l& F& j) U' T
- var viewportwidth;! |, d+ G. v* w, O# Z/ l
- var viewportheight;" Z& x; a3 B& |$ F4 P: V% n
-
- D8 p% c1 p8 `5 U/ [$ k - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
( n# [4 Y: j* j$ x -
; c" t; Q0 q% B# h - if (typeof window.innerWidth != 'undefined'); b) c# U3 N# g& W: t+ Q
- {
- G+ _; V4 V& w& Q7 k& \ - viewportwidth = window.innerWidth,
9 c! D7 p8 Q( {4 J. K% ] - viewportheight = window.innerHeight9 F, s$ P. j ]1 D# D
- }
. p) u8 g! n8 T3 U6 [6 o" r! u - , U% \' {* I4 _( G* U2 q8 `
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document), k* E8 t& z+ @! x: q
( @& H" J5 s9 N2 F& t/ T- A1 |; W( t4 y- else if (typeof document.documentElement != 'undefined'2 f/ V$ W; r4 `# u2 J
- && typeof document.documentElement.clientWidth !=
0 f9 {( a. p, b6 L( _ - 'undefined' && document.documentElement.clientWidth != 0)
+ F' N$ P/ R7 S1 J b& I - {
5 s4 |" m: Y" X6 N0 K, m2 w3 T, E - viewportwidth = document.documentElement.clientWidth,
8 z3 Z" a3 c! B$ ]9 m6 D2 x - viewportheight = document.documentElement.clientHeight
! j; {; C6 a1 b0 o! [7 h6 Y - }
- L* e2 x3 N0 m( a -
9 h& \2 |, f/ [1 k; |1 Q0 Y& \ - // older versions of IE
3 @4 e. O, K/ S5 \$ d4 O -
! V3 d Y4 h1 b* F# z7 F' q( f - else7 a' k" q% p S w! o
- {( K) M( `, g& m
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,% F ^. s) ~5 i6 V
- viewportheight = document.getElementsByTagName('body')[0].clientHeight
& m* u$ R. W% H- N: K' W( X. y - }/ D3 s- Q5 d6 Q3 k
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');2 _; @+ A$ y& x' L+ h, {' O7 b1 h
- //-->
y0 {4 T& g$ |: \ - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
m' N7 W: m6 U8 w( z% B6 J' e
. A$ G3 n# ?! S* p" ]5 P4 a1 }% E8 o1 [$ J% b8 A& q
靘皞: Get viewport size (width and height) with javascript
( W! z$ m- E: _$ v4 v, @
; K# r' U: r8 u& E! @' {2 m. P
9 `4 x0 N+ [. }5 A; c1 q |
|