砍敺 media 2014-12-10 19:08 蝺刻摩
" p$ v, F0 O: r2 Z# m2 F3 F- d! K# { j% x1 Z& e7 A' P* c9 |6 }
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具) R" w' J3 B4 f
- <script type="text/javascript">
& }3 t j1 H! }8 {2 Q0 { - <!--
. c2 Y) }& K' P# u* o- P1 z5 C- e
9 _/ t5 f- i' Y0 T- var viewportwidth;$ o* Z1 M- Q) J" T% l* V: m0 M
- var viewportheight;
- Q: q: s7 ^0 R -
0 F& ?, i2 A8 N4 x! t. k - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
+ O# U$ n8 W4 X7 i# j2 ]& { - 9 `' g0 F' w4 @1 Q! ~' m: i. ^& z E
- if (typeof window.innerWidth != 'undefined')7 N3 w! c6 a! C7 O% W: s
- {, k z" s6 W1 ?( r& B
- viewportwidth = window.innerWidth,
! Q2 k9 l+ A: ^ - viewportheight = window.innerHeight2 p7 a2 q$ g2 X9 k+ J: O
- }
" T, S& ~8 N! [# h# r$ D/ m: p, g -
6 k- X5 l% W8 K b. y, s/ O# ^ - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document). b9 v' }7 t& I3 k/ x9 e# s! C* [
u3 T+ U2 ?; p9 T- I+ F- else if (typeof document.documentElement != 'undefined'
+ [4 n1 H8 e1 n( z - && typeof document.documentElement.clientWidth !=' E P0 D2 w/ T0 c6 D6 V+ u$ z
- 'undefined' && document.documentElement.clientWidth != 0)
& [- h% h( o" F5 S5 k$ t - {
9 K: ?/ q! z$ A& R9 r# H$ g+ ~4 Q - viewportwidth = document.documentElement.clientWidth,3 z1 V; A0 Q: M+ d* r# B' g' p$ k! L
- viewportheight = document.documentElement.clientHeight) O2 g* Y: l! A1 c9 ?7 J0 {
- }5 ]6 P- X) {# g1 b1 d
- / n9 Q/ R" n" A0 H, d& g0 ?
- // older versions of IE: N3 ?7 U ?4 e/ y7 j" m' Q" v
-
: Z9 V3 N8 `1 A- O: _2 \ - else2 z9 [" F3 Q7 A) }$ W) R; k
- {
T5 s* X+ O$ L2 M3 f! K - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,4 q9 V8 l7 ?3 k, W
- viewportheight = document.getElementsByTagName('body')[0].clientHeight
; o, V5 d6 C# O( ]: V - }7 T( ^3 p7 f- D7 H. B1 o
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');' a9 G' Q$ G% j) J
- //-->
4 O1 j- C0 A5 E4 b. C8 h- E8 K3 L# ] - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯6 @' ]9 y9 f5 E) t# v( O+ R
* ?6 o2 G0 k% G
, ]' J# B8 b0 A2 Y
靘皞: Get viewport size (width and height) with javascript. S* @0 w- O1 I$ W v* }, e# o
4 F% z1 n( B: V3 M7 i# i1 J
1 x+ ?) b# y& x! ] |
|