砍敺 media 2014-12-10 19:08 蝺刻摩
$ }, I) n0 }; T7 V" z+ H+ ^& R& `- i% \! a9 a1 l. `! d3 I
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具# F) p* w' O- g4 ^2 o9 ^! q
- <script type="text/javascript">( D; ]# y) S5 [2 L4 Z' ^
- <!--4 t) ?" ], h2 [4 ~/ [* S8 F! d0 E
7 r8 j1 C) J2 B! S \+ P- var viewportwidth;: V4 l4 h0 n* m, t
- var viewportheight;
" T- @ g% `. Y5 F' I+ } -
( }& O$ s( z" ^) x9 \; F, W; P1 n - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
9 h! _& S# X; w: _$ ]4 G/ T# Y - 7 I; K# a4 x* [# E
- if (typeof window.innerWidth != 'undefined')
9 W3 [" p& @% b! W' _ - {& Y' ^! t& U6 n( J0 }) O
- viewportwidth = window.innerWidth,9 Q6 C. v7 n. Q$ t
- viewportheight = window.innerHeight
1 M+ N$ _+ `5 K/ L$ n0 A& d - }
. u/ p+ G1 g+ U4 p0 h1 k7 G - 1 a1 S G$ T* v/ K8 [4 B$ l' W: b
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)" J% N# H7 n2 q- v$ p# M; [0 [
% q7 x5 b. m( j$ O c) V" [- else if (typeof document.documentElement != 'undefined'+ Q. W" M- w5 m: n; A
- && typeof document.documentElement.clientWidth !=
% U& g3 P! Z5 J! T/ L) m i - 'undefined' && document.documentElement.clientWidth != 0)' |. T2 ?. V, ^ g$ {/ m
- {! I/ |% {) l' l3 [" V3 @+ x0 J
- viewportwidth = document.documentElement.clientWidth,/ Y/ g4 n" n+ h1 o4 m1 J! j% V
- viewportheight = document.documentElement.clientHeight" `7 P) y# R6 D% h% D
- }/ f) t- W8 H; j8 i9 O% _
-
: Y& j; B* g" `; P: L0 x4 ` - // older versions of IE
% D. c9 |0 A# p7 Q* v5 _! o -
& `+ b$ C. n; G/ E6 R$ _1 Y - else1 [, g* \. F- J$ ~6 L9 n0 I/ n
- {8 N7 V# O% N! V0 N) ]# ]5 n. V
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,' e" k3 F/ Z1 e& ~4 H; P* I
- viewportheight = document.getElementsByTagName('body')[0].clientHeight" P; r' J J' r. o
- }) J! ?' v* {7 F
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');0 ~" P- O' _0 f
- //-->, N u9 j7 y# O+ a) V* U+ ^
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
K6 w( o$ I/ |- Q+ h/ n4 \
8 F% R/ x+ ?, H0 e$ r6 A
" g* D* r0 V+ R- b靘皞: Get viewport size (width and height) with javascript
9 w6 r5 P! {" Y
: b2 o$ P7 J3 S9 W* v
: Q4 E3 j$ K) }, Z |
|