砍敺 media 2014-12-10 19:08 蝺刻摩
' ?1 c! [; w0 o1 G' N+ w9 B" I( h0 X7 Q6 a+ r* ?3 H# ?0 Z* O4 D
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具3 l, Q! R! K. E9 _- w
- <script type="text/javascript">
p5 _- q" p7 u' e6 `6 ~; H - <!--' a) b/ m6 l7 v. Z# G
, m, x1 v; c/ v3 h$ t- var viewportwidth;7 l+ Q: F C T6 @. u4 A( s T
- var viewportheight;
, t4 y: g9 P6 |7 s! Y! Q& C -
U# i- j& b9 Z" H - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight6 P( z, k4 n9 E& R1 i, }, X( ?
- 8 q2 n7 ]+ s1 |1 W) P$ D
- if (typeof window.innerWidth != 'undefined')
6 f6 @$ e- H! M! m/ _; q/ \ - {
5 g& I/ M! |. l: d2 z# g: l - viewportwidth = window.innerWidth,- B6 ?( m; o, q3 T% E2 B: e/ f5 k; y
- viewportheight = window.innerHeight6 v' M+ Y) @% A0 h
- }6 w' c' U$ a( @3 _
- ) Z/ B$ g% o" c" @! k
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)6 v+ t2 {& [' D \) X
# e' r% G/ k( d: z- else if (typeof document.documentElement != 'undefined'- s0 Z2 H: V/ R) _) z
- && typeof document.documentElement.clientWidth !=
U6 l8 M$ p$ C+ Z% J p1 }# o7 S1 d - 'undefined' && document.documentElement.clientWidth != 0)5 V7 Y; o3 H6 j
- {
+ W H! j9 O ?% t% J7 ^* K* X - viewportwidth = document.documentElement.clientWidth,
1 Y; k) J: b- R" Z6 X- R+ u2 o3 k7 `" n - viewportheight = document.documentElement.clientHeight
5 N9 V/ S9 Z) d1 c! G - }2 S% C4 ~' S1 v( y( T* s" }4 p
- 5 g! k, I5 a9 @3 O, n
- // older versions of IE* W; V' ?5 m+ }, v# ~4 |: b
- U3 f$ \% U3 Y
- else0 o5 g3 \9 t* [. R8 ?
- {
3 _$ T* ]2 L2 k7 ? - viewportwidth = document.getElementsByTagName('body')[0].clientWidth," C; \' E1 `- A# ]# p! p% t5 n3 p
- viewportheight = document.getElementsByTagName('body')[0].clientHeight1 q' i2 ^" N9 N; @; h& Q& H
- }7 o) i& P% I; T$ b6 F
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');1 Q) v4 a! h7 j5 v) @4 h& x0 F
- //-->0 t) P/ q7 @+ T/ p% T
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
1 H2 K# T0 q# x; h2 W' r, X$ @
5 |6 k+ T. C: x! n/ ~* _4 z0 H" @% ^8 `3 c
靘皞: Get viewport size (width and height) with javascript" M5 B0 q4 m7 {, s! t' T
4 W! _+ e# y: e* _% k+ `1 ~, A6 E8 Z; U' q" [0 o$ E
|
|