砍敺 media 2014-12-10 19:08 蝺刻摩
# ~' U# h5 J K) r$ {2 E5 H6 ^) A: \0 u
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
5 A: w) y5 i g2 k) |- <script type="text/javascript">
# g! J; s: P3 {; `+ D# p1 s - <!--
3 Q, L% m7 c" V Y - 7 Z5 ~- s- s& I( d/ y" ^
- var viewportwidth;
0 b+ q* b! P& r5 l& ]/ T2 E/ U0 G - var viewportheight;" A" X1 e& X. r9 ~2 B5 M% y
- # e( F% K( c+ n# p1 B8 B
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight# y( m. K& H' V7 s8 c' s' T e) [
- 2 a! m Z0 m$ @+ }
- if (typeof window.innerWidth != 'undefined')0 T& J5 B ?& g6 K
- {
]3 r }5 a# q7 r - viewportwidth = window.innerWidth,
, u8 _8 j0 z8 k% \ - viewportheight = window.innerHeight
* P1 X$ d! ~1 A - }
! g, R0 H! I1 N - " \& ?5 d0 o: z8 T- D
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
- C, K7 e+ t5 \; p
; t8 E( k9 c4 B: N( g; c+ B- else if (typeof document.documentElement != 'undefined'
- l6 I) F! h2 G3 p$ W+ m - && typeof document.documentElement.clientWidth !=
* ~8 }* p2 |6 w& ] - 'undefined' && document.documentElement.clientWidth != 0); B& H$ K) M& q/ N5 _: D) z r; S# _
- {
" T3 D0 V# R3 T; f: c+ P - viewportwidth = document.documentElement.clientWidth,
1 a3 a2 ~0 y9 U. W7 u; N/ p - viewportheight = document.documentElement.clientHeight
B7 a0 h. u8 N9 R6 ~5 d, V - }
, P, t( Z$ ~& R# @. S* I -
# z4 W/ T3 ]6 x H) O - // older versions of IE1 a4 ]: e G9 p, A! m9 m# h7 Z! n
-
$ J( J2 y$ H! R" H - else
9 J* @4 U g% H( a - {, I" n4 \4 o1 S4 v/ E' a8 \7 b
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,: B7 q4 _/ e1 R: ^( K/ F$ R
- viewportheight = document.getElementsByTagName('body')[0].clientHeight, U* X, l+ A- E) ~
- }3 b& Y) U7 m- E" N. C
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
' X3 _" x; q- A" g& L - //-->, i& \7 L( f p% _1 g+ D
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯& B8 r R/ o2 m6 Y1 l
0 R3 H% M+ i& V3 J& t. X% y T
7 K; U+ j2 a0 F( A靘皞: Get viewport size (width and height) with javascript+ D1 w' v+ Y9 H8 `3 C$ R$ r6 W; v
* Q4 ?" E: B2 T3 \4 b; i z. ?" f5 Q: ?3 |
|
|