砍敺 media 2014-12-10 19:08 蝺刻摩
0 ]: V* S+ Q! a; N7 i. p' A1 ^! @, f+ b
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
6 s- E5 F( R2 ]2 ^2 N- b- \- <script type="text/javascript">
4 {8 O" D) h' V. K$ _! b* W - <!--7 x+ O( D$ G a( O1 X
1 w& l+ x0 D1 L( j* f% M- var viewportwidth;7 [& y! B; K* k$ h& x- S7 B( _8 L2 N
- var viewportheight;
4 V5 w# v9 p" U6 ^5 P h -
( n8 V- K4 i5 B$ Q9 ^$ G - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
7 F* w1 z/ x1 P - + r$ a4 b( i E } k6 x
- if (typeof window.innerWidth != 'undefined')
7 f- h( f' L- h, _3 V - {
. C. n3 g# K9 @0 F1 C - viewportwidth = window.innerWidth,
3 M8 P* G1 B2 i+ U( z - viewportheight = window.innerHeight7 }# y5 a0 O9 d4 D+ Y( i$ J
- }) E1 X* m4 T p7 r0 M8 l3 k# g
-
, I( Y: Q3 ?0 x* |2 V. U; J3 @. u - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
' ^, g% v4 Q* j* d M# P! Y
8 O/ y7 f+ [% c# v5 Q7 x- else if (typeof document.documentElement != 'undefined'
) T1 K5 s! C4 } - && typeof document.documentElement.clientWidth !=
% w' z# n$ w0 t: M3 l+ {# I - 'undefined' && document.documentElement.clientWidth != 0)# T/ ~ \. I6 d
- {
. d- R; M; c* U6 R P1 A8 e - viewportwidth = document.documentElement.clientWidth,
& f& z0 f# k" Q( U3 G0 O4 {5 @ - viewportheight = document.documentElement.clientHeight
! j7 @4 n+ g. I5 F' h: \ - }
* D3 B$ Q, @! C( Y( T -
. p6 Q i" A/ T, V - // older versions of IE" z7 T, u0 M4 u' o8 o
- d6 Z; [6 d! a6 s. o
- else
$ D K* ~# x- ?4 F3 x& j+ p - {
5 O/ s$ W, ~* y+ p) R - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
" N* W2 H* j+ ^& X0 W+ i - viewportheight = document.getElementsByTagName('body')[0].clientHeight
: y& y8 f ?! r$ U/ u% E& f- I - }! |; a) Q* K; D( t; E7 X
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
3 @: g+ E; ^; A, x+ O - //-->- m, F4 ]8 x' D6 G0 S) z
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
5 `) K* a: s3 ?4 y9 ]6 r' }" ~9 k5 A
8 }* R) P. V: j {# H$ ?
9 t# l2 f, s1 Z i% @1 ?
靘皞: Get viewport size (width and height) with javascript
" f9 [# S# w: L$ a* ?7 R! j. c. M
l; T; V1 Q% y" z4 L: F' J0 B/ f) B: i$ x$ C8 T
|
|