砍敺 media 2014-12-10 19:08 蝺刻摩
0 @# E' c/ p; a) A
7 L3 n, \& l8 j3 F! |餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具2 t, r Z5 ~2 X5 ~8 c& e* v2 s8 N. c
- <script type="text/javascript">
/ C4 a* X) y& u% { - <!--
' q1 K; S* B5 g
( F: F; `3 Q! e2 r) c+ I% |- P, K1 e- var viewportwidth;7 i9 z3 H" C3 P2 y
- var viewportheight;
/ f1 e" g6 d( r% L7 x( k* Z -
Q1 y# F- k1 I4 p, ~" W - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
4 a' f, M; `* A4 }5 @4 d - % X6 @6 T/ T. N- `6 ]* |
- if (typeof window.innerWidth != 'undefined')0 Z. Q$ U' _# z
- {
3 x$ |* w7 a2 T8 t" F - viewportwidth = window.innerWidth,4 M1 W4 R/ P% L U+ X( N5 ]
- viewportheight = window.innerHeight R" _6 _+ ~& T) K( u3 G
- }
?# o/ y$ x/ Z - 0 H- ?( w9 c; R% f% r$ l4 S
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
6 z; b+ {. c7 ?# l. s0 o - 8 E0 |* O% o! [) p1 D6 B: f8 p0 t
- else if (typeof document.documentElement != 'undefined'. ^- F- y' T: W$ H$ c
- && typeof document.documentElement.clientWidth !=% ^. v! \( N4 b' q8 I3 a% R
- 'undefined' && document.documentElement.clientWidth != 0), y) N3 c8 P3 u8 w/ d, f( E
- {
9 e8 I# U9 f4 n# x% H6 ~ - viewportwidth = document.documentElement.clientWidth,
4 e4 ^: b2 r3 |% C5 A; }4 t - viewportheight = document.documentElement.clientHeight) k2 ?' Y/ A2 s& v0 s+ s% N' T
- }
* E! x w! q8 s c, t7 I -
2 W" G. p! f0 Y7 z - // older versions of IE+ ]) w$ d4 l+ ^5 X5 l
- % z. K: v6 \' O7 G. c' m1 r
- else
+ B8 b% a' ]; b+ i Z. g - {# {9 `0 `2 _+ U1 b0 z" `7 |
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth," J$ h1 {: Y, A6 h5 s7 l6 \0 E& p
- viewportheight = document.getElementsByTagName('body')[0].clientHeight
& n, Z) U# S) H" ?: \ - }$ u4 ]. o) c% l# X# t6 ^
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
+ t% G5 h$ n0 g; m, N3 b - //-->( [2 R2 d$ @1 `# [6 X! Y, T1 c* m
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
7 p6 ^6 N' r6 W- {3 Z1 D
9 L. x9 C3 H$ a( R
( f" ^7 Y# }1 V( a靘皞: Get viewport size (width and height) with javascript" {/ j g; P' B& M' ~
+ T3 X, a" O; \) _0 s4 h; P
# l: z) P9 I( Y5 t2 r) _ |
|