砍敺 media 2014-12-10 19:08 蝺刻摩
- L2 t) |% t8 a( C3 \7 v c& ^7 H/ u& V. M- e& ]3 i7 ?' r5 O' S8 B! J
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具" K$ O( s, t: J8 U9 L
- <script type="text/javascript">
0 _" X; |6 a# f+ w0 _ - <!--5 J( |1 ^/ B f' Q( O* x$ h
- 0 g1 M( g9 f' q7 i6 N; M/ x4 f
- var viewportwidth;
* K- [8 `+ h) y _# l5 ^. _9 @ - var viewportheight;2 m. @" w$ d6 m, A% ~: [4 t5 V
- 6 }- V+ w( ~/ F" W9 B, S$ d: M
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight+ \4 B9 I/ M% Q( ], C
- 6 A4 B' [) j2 h+ g" H9 _1 ]
- if (typeof window.innerWidth != 'undefined')
+ i" O/ K: M$ o. I$ g5 k - {
& c! [% x. }$ a7 [$ c, U' G! k) v - viewportwidth = window.innerWidth,5 I/ |; O: ^- L7 ~' S$ O7 x
- viewportheight = window.innerHeight
6 W& Q7 @7 z$ F; ~7 q) D - }
4 r2 |! F6 Z; _% H1 O9 _; O -
) i: f# Q# L. D. I, ~, S - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)- Z# R; ], B z! B
- & u; a c' e2 O' i1 q6 d
- else if (typeof document.documentElement != 'undefined'0 ^! G, @- N' Z, Z
- && typeof document.documentElement.clientWidth !=/ f% V/ k6 |/ t3 {
- 'undefined' && document.documentElement.clientWidth != 0)$ l% M4 t3 S* H' } e9 v5 A0 ^
- {$ E$ _$ _7 l/ J$ s$ p' J
- viewportwidth = document.documentElement.clientWidth,
( ] }0 W [: R/ n - viewportheight = document.documentElement.clientHeight+ W: r& [5 l6 c$ p' |
- }
% A& D F) ?" d8 f, p' { - , _1 n7 Y2 h5 @+ _8 b! g
- // older versions of IE# q; }! p: A+ M( @5 w0 w# d
- $ @2 C' k ~. v8 H( s$ |
- else# B- e6 a- ]5 v& _- V
- {0 {6 i- [) I+ U+ _' A3 |
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,# F& P/ r% [3 _4 s+ ~
- viewportheight = document.getElementsByTagName('body')[0].clientHeight
( x L" e0 K0 `! C& { - }
' u- H# ?' L; H4 @) N - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
0 L0 e1 i6 ]6 F8 e, n* a - //-->
+ ?" {0 E6 n! h, R d - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯) E7 }" M% C' l' g7 j7 z
6 f; |! N; P, K" s7 Z; }3 T5 I5 Y" B
靘皞: Get viewport size (width and height) with javascript
`$ |; p$ F' L t7 U$ v q3 A% E @3 g4 O ^+ ~1 R& u
8 b2 U6 t1 ^# v: j
|
|