砍敺 media 2014-12-10 19:08 蝺刻摩 # n1 I# M% n3 D; \0 [ N/ b
' i3 a& J n4 v% U7 [; e
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具3 ], s1 f& Y" p6 J/ _- a
- <script type="text/javascript">
; ]: S; A% }$ q0 I, f$ Y - <!--) |: z: u. w. o, Y7 ?& y* C
- , q% Y3 I3 z. q% R% G) ~& O
- var viewportwidth;7 U3 r8 C$ M2 q' T: ?7 b. u& X
- var viewportheight;( {- M* ~6 x; j% v
-
* F% }: [) s. D2 e G L - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight5 @/ M2 f5 P( `% M
-
! S8 }* S+ d* p - if (typeof window.innerWidth != 'undefined'); ]' }, S/ o& g7 Y& U+ S: G$ \( u
- {
: j% I6 s0 R! _! } - viewportwidth = window.innerWidth,
3 H. p! n% e* x$ W2 u - viewportheight = window.innerHeight- Z0 [" ^2 x( t* Q
- }- B1 [7 z. F) P; [( n& P- R2 O
-
/ }7 O/ F$ K( ^- N5 Y4 k - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
, ` w0 |: a9 m* c- z! _' ?5 Q - 5 S/ N3 N; g% E
- else if (typeof document.documentElement != 'undefined'
' ^0 y. {. l1 j# b x+ o - && typeof document.documentElement.clientWidth !=
7 a$ p$ G: Z3 g7 g0 ~+ { - 'undefined' && document.documentElement.clientWidth != 0)
. c0 v( C; E u$ A4 n - {
1 ?5 H" O. t5 P- I - viewportwidth = document.documentElement.clientWidth,, S1 o" O& S) K; H0 q
- viewportheight = document.documentElement.clientHeight
& _ D0 ]* c+ R' ^" }3 o0 i - }
: R* A: m/ \6 w4 b$ P4 T2 } - " _1 D; ~+ h7 m; W" T9 G8 V
- // older versions of IE0 ~8 w* [& C& t) Z
- 1 S4 g& N t# _$ i/ b9 R
- else& h$ M Y* x% v+ g0 z
- {
% D9 [# M* Q/ r7 [ - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
# n, z% e& {; G9 | - viewportheight = document.getElementsByTagName('body')[0].clientHeight: A* i# M* ~# h- A8 t: J
- }' a( m/ Y/ }& u. o7 T: M
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
% d4 ]' u" ~. S1 l6 H, d- Z6 h - //-->& G: h- n* g" p2 g+ a2 O
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯, i7 _; m4 W1 ]9 m( ?3 [) d
- P5 f$ r* ] A; g' O( ^/ r
9 h( ^; v6 C" I" w% [4 c靘皞: Get viewport size (width and height) with javascript+ _9 {/ L& f9 m8 n0 E! d* l
. ~- B e' c$ @, M, k' n7 P; @, v7 N2 G7 P( m" G2 L
|
|