砍敺 media 2014-12-10 19:08 蝺刻摩
5 t- U% v u' ?8 y1 W" Q, U- i+ Q3 |' ]
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
- W0 |' X4 l, E/ ]+ I( B1 }- <script type="text/javascript">
/ ^- d( ]$ T; _" I- E6 c - <!--
& D b5 x* S2 S! V" F, r* W2 Y
3 y6 B% d5 o5 C' h$ }- var viewportwidth;/ [3 `& L% J: X, D2 Z
- var viewportheight;: ~; R8 t; K/ K- S C6 Q
-
4 N3 c0 B' D8 x1 C- ]5 o, o( X- y - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight; Y+ _& d' L0 k0 S* y
- ' G, u" n. D: u/ S) i: V" v
- if (typeof window.innerWidth != 'undefined')) Q6 d5 H( E- _5 C# t4 f
- {- X {1 `: n9 P; p
- viewportwidth = window.innerWidth,
5 r) m1 i1 S8 J! A& a Q8 z - viewportheight = window.innerHeight1 Q7 I- S; s7 Z' Z( c2 N
- }2 c2 ^3 W1 U6 o, A1 M' L
-
, e) o: \+ q# {% {& F - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)5 ]& m; U' {6 T* b
- ( t) w( H0 q7 b# |
- else if (typeof document.documentElement != 'undefined'- R9 j+ N* q$ p' B* g1 D( p( N; H/ A
- && typeof document.documentElement.clientWidth !=
, u6 A( V' S, s, X; |: H# @ - 'undefined' && document.documentElement.clientWidth != 0)
8 ^7 }$ m$ U3 I2 R, ]1 f* k - {) M% x0 ]! E3 ~9 }* J" n# F; K
- viewportwidth = document.documentElement.clientWidth,
( Z! p$ e% w: z. |- J - viewportheight = document.documentElement.clientHeight
$ Z" Y( x: R2 ^( w - }
" O2 o5 E$ P- l; _' V - 0 |8 Z% W! K) l9 `$ W
- // older versions of IE0 E6 x. t, B* X- S, w
- " k5 K" z m! {" v6 f9 c T) M
- else( t! M7 ]' V4 T- q2 M: T$ q4 Q
- {! O1 E) `( G8 j- Q- }
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
$ ^3 D' w" V3 E+ o; k9 A - viewportheight = document.getElementsByTagName('body')[0].clientHeight
3 U3 V+ X. d! \7 Q3 ^ - }
H$ z+ _- J$ h+ d" X! H: J - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');: ?6 y/ J- d( k
- //-->- r. W& ?7 X" ^9 E$ I
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯; {' c/ B0 z. z" N n3 M6 z
/ O5 ^" ?4 T$ R$ m! v7 u6 R
5 ^9 P4 [5 l; _) L; N
靘皞: Get viewport size (width and height) with javascript2 _& m5 e/ K0 a Y! A' a. M/ x, d
* L( k/ P5 ^2 r% ~8 c' D0 `' n4 J. ]4 i$ p9 P. A4 C
|
|