砍敺 media 2014-12-10 19:08 蝺刻摩
( n- s7 \3 Y' Q! R, w% b" q' D! E% G' S- v8 c) G
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具0 f1 l: F) E0 @
- <script type="text/javascript">
& b( C/ n4 m1 a0 t8 Q% a - <!--
2 Y( T$ n- K! T% q# b x
4 [ j* N1 W3 S7 N# K. e9 C8 o- var viewportwidth;
# y% t; M I$ z* _% [2 t, a- l: a - var viewportheight;
: s2 G, x% R5 P: I6 m! i$ l: x! d - " M5 t9 g! Q2 I) ~) @
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
, H% B9 C# s3 Y8 ~ | -
+ i+ w* X8 o5 K6 k0 _; k! x5 n - if (typeof window.innerWidth != 'undefined')% _" U/ s4 O# n# i" N& P
- {% O( c% A% @7 A( e6 }# W6 Y# C
- viewportwidth = window.innerWidth,8 o# k) v4 q& g" e* Z* `
- viewportheight = window.innerHeight
) L9 k7 N0 R* f) Y; ` - }. N, N8 I+ L9 ?4 h$ N
- ; r7 O' f+ E: b. f' { N0 G0 _
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
( q9 j( a5 z" S. v7 } - ' ]; s5 K; G: u7 S5 z
- else if (typeof document.documentElement != 'undefined'7 s3 ~ z& ~, q5 Q) D" M
- && typeof document.documentElement.clientWidth !=
; L6 [" v: ~. b: X - 'undefined' && document.documentElement.clientWidth != 0) G! n$ B F+ ?. K" K( B3 p
- {
: ~0 G; u# _( H/ s - viewportwidth = document.documentElement.clientWidth,
! M/ z2 G5 Q9 I& `- ^) ] - viewportheight = document.documentElement.clientHeight0 A$ z9 L2 Y& d. ^: c$ k
- }
2 L4 k0 R @6 ]6 F1 m4 E8 W8 I -
' r% F+ j( e0 d, J) n6 o - // older versions of IE
$ ]! g) n$ R0 D V$ `2 Q -
1 D1 T9 c* V i* s' j - else
* [2 h$ s0 W0 z( P- | - {
" h; y7 v; |5 ?+ o9 o* q k - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
, E O6 i" x& W4 o# A- g - viewportheight = document.getElementsByTagName('body')[0].clientHeight+ q( Q9 W7 I! r2 ~* ^
- }+ a* F- a9 D/ G$ u) |* m! O: C
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');" x- |. `) t+ ^+ M* t( Z; ?6 A
- //-->
0 J; j% s% R/ u# W# h7 E - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
, `$ S5 X6 m( ]: H, K3 }
- N" o7 G: j0 H9 C8 ]/ m3 Y
, H5 S+ w8 u4 i8 m& ]% B靘皞: Get viewport size (width and height) with javascript, y) R' T0 k" c! d4 P0 D
1 m/ N, m: Y* S8 ~) @2 s- D @. s) {' t7 O0 a S2 Q0 U
|
|