砍敺 media 2014-12-10 19:08 蝺刻摩
+ ^* A, T: _ X
/ s* G7 c [" S; }# |5 @餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
7 v! S9 Y- K0 \8 m3 c! S- <script type="text/javascript">
; P' ]6 ]) Z: y, m3 [. `' e4 Z' P - <!--% ]& h* m- P b: s. W1 x
- 0 d: D; o) j; g1 b: a3 i
- var viewportwidth;+ P7 D' `; |- G1 k. K/ v/ M
- var viewportheight;% H! j/ q# t8 Q) D
- # j$ G8 f7 ]6 d: F) |. J
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
! S0 T* e3 E: U5 E - 0 _' b9 q6 M- \, \
- if (typeof window.innerWidth != 'undefined')7 x. I- p' I1 E, k
- {
% ^9 v4 p/ g' E! u4 ], ` - viewportwidth = window.innerWidth,' K5 K# |) A0 Z1 J* F
- viewportheight = window.innerHeight
4 F0 y4 h1 `+ f s, V; Z - }8 L7 Z. F) s% H2 O% p* ~
- : V' ^. E5 O1 w7 |, D
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document): m3 m% b2 h" n2 C3 f9 ?- x
- ; Y) L4 P: F2 q0 ^
- else if (typeof document.documentElement != 'undefined'
) }! `6 N- |% `9 ?- F5 _- p - && typeof document.documentElement.clientWidth !=
. c( w& {: I2 {9 y) c+ e4 K - 'undefined' && document.documentElement.clientWidth != 0)1 q% n. ]5 f5 k" n0 M; M1 q8 N
- {" T% @, I( C4 B. b; @
- viewportwidth = document.documentElement.clientWidth,
8 ^9 P3 Z+ u9 b' N1 Z w: F- V+ _2 H - viewportheight = document.documentElement.clientHeight
7 O' S# m- W, z8 ?& N1 A - }
8 s( z! U; r u, L2 y/ _+ ^8 d -
3 g& a, ~9 C- O2 t0 j" P - // older versions of IE
" F8 C8 H- ?' e$ H& r8 G - / ^4 U1 G: R, ~
- else% D& `8 r- b! y
- { o! Q" Q5 X) @
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
& }; k) y. N- l2 g( [ - viewportheight = document.getElementsByTagName('body')[0].clientHeight
1 l2 h# ]$ B* i2 @ - }
; S5 d, p, _8 [- x$ A+ J - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
7 T7 p8 ~. h4 L% O( u, `- k - //-->
5 k5 i6 u# S: I, x/ t - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯/ @' }7 A/ f2 {9 t" j2 F
7 Y- Q$ E$ b/ L) S
3 |9 n$ o- m! K' S0 Y6 t: }
靘皞: Get viewport size (width and height) with javascript
: V0 d7 i, Y& e/ R' V" r1 Q* c" c$ K4 G
! k$ X( g2 j7 w/ ~; X& U |
|