砍敺 media 2014-12-10 19:08 蝺刻摩
- L! F. A* @) O+ N* Q1 G2 Q+ v. d" x( r2 o5 h/ C6 O
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具5 o' M5 Y: w+ u5 |2 G7 b( r
- <script type="text/javascript">
: C+ Q, [9 W: y1 J$ @( n# O9 D7 k - <!--. D# O2 _) F) u7 W8 D/ a9 `/ ^! a
s# ^$ F3 ^9 n% S5 Y. V5 f5 x- var viewportwidth;7 a l9 U& F- }& \9 M
- var viewportheight;( l* H% Z" ^3 O0 G
- 6 P# x" w, D( ?7 W
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight; O0 t" K3 I6 m0 D6 d
- ( D$ P4 w' K/ J; W( `( J' W
- if (typeof window.innerWidth != 'undefined')
- A. K0 t- E; G - {, }6 F; t& O3 b' [6 _0 |( g
- viewportwidth = window.innerWidth,
+ g& g" C) L2 O" k - viewportheight = window.innerHeight5 @9 i, Y8 P! b1 m
- }
3 S0 s4 `* B6 ]4 k2 i6 k - + Y- A! W' ~; r. W/ Y F. R3 I. w/ a/ x
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)5 I% a* ~/ M% L1 X% b
- + Q8 Z: }4 ^2 y0 |8 G) `
- else if (typeof document.documentElement != 'undefined'
8 ?2 r% h2 T+ v( j+ G [% Y - && typeof document.documentElement.clientWidth !=. @( `$ P8 u+ s$ {. e
- 'undefined' && document.documentElement.clientWidth != 0) q* l! O) o n0 {: {4 A# x
- {1 k1 h9 f4 m3 q+ U6 d; B# }9 U) h9 t7 e
- viewportwidth = document.documentElement.clientWidth,
. t3 Z' O5 M3 F4 O T4 g% f - viewportheight = document.documentElement.clientHeight
1 r9 I' I3 ^* { e& ?, S4 I' ~ - }
; F8 c, d% ~& T" G6 Z& C) m* d* Y - * f+ V; m: Z0 _0 p: ?1 D5 I
- // older versions of IE Y* U) W5 e* F
- & h) h$ k' o: ^; Q `& U
- else
8 m. z$ h# Z( Y) I' z8 u - {
* N9 W0 E8 w6 [7 Q6 e) G) H) ~ - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,8 I5 @& K" J- K
- viewportheight = document.getElementsByTagName('body')[0].clientHeight
% w# A- [ h( @/ I( b - }
# D/ A M" J, i$ Q% Y5 d - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
- i' {4 o9 W- E6 B% F - //-->
) k( [" f# v5 V9 C7 ^ - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯9 j s/ m" K9 y
6 e# K2 M) u0 ^9 G8 G/ I5 H$ A3 J
. n% E2 S( g {7 Y靘皞: Get viewport size (width and height) with javascript
6 M, \ m( P. t+ x8 [6 e
, o {1 z) s0 j! O! y: b3 n# f0 E1 D" n6 p1 u
|
|