砍敺 media 2014-12-10 19:08 蝺刻摩
7 w& S$ a; c, s! B5 w9 G( u6 C
) H0 ~3 G% Y, e. P0 W餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
7 @7 b( O0 d# { C# W* s- <script type="text/javascript"> t$ r- U0 f! W- d
- <!--
8 Q: r& }( m; r8 M: _( e3 g4 J - * ?6 y; T. R2 Z8 [* X4 E1 _
- var viewportwidth;$ ?( m" o0 X, L! j/ G) }$ b
- var viewportheight;
' g4 I! a1 c2 d/ J! ~9 z [ - ! @6 v) y$ u0 L: A+ U: J) g
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight9 M8 `( V4 O- X& Q& Z
-
0 |4 [& h# J# ~# a' ]( k! [ - if (typeof window.innerWidth != 'undefined')) K4 g; i9 j$ S3 |
- {
9 s& D3 O6 x1 Y7 f2 |% I2 e7 C, W - viewportwidth = window.innerWidth,
0 b& t8 F/ f' ?$ n! i* X% {& y - viewportheight = window.innerHeight
- Y" D E# e* n0 V% y% r i - }
" V: P0 [9 Z0 @) h - 3 y4 I% l! T% F! x+ l) o
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)+ V) |' G4 o' [
- ) f1 a9 Q0 i. O" I8 |3 h4 S
- else if (typeof document.documentElement != 'undefined': `, M/ T/ X& F/ Q N2 A
- && typeof document.documentElement.clientWidth !=# ~8 J( g( f( P7 b& \1 u% @& ?; U
- 'undefined' && document.documentElement.clientWidth != 0). k5 r1 V. B# z9 C0 {& M
- {+ N/ ]/ d0 N& a8 _; [/ C5 T6 R
- viewportwidth = document.documentElement.clientWidth,
! z# \% `3 I b6 ?; s - viewportheight = document.documentElement.clientHeight
! F2 j* u2 V$ i0 e - }2 n( Y* m( U/ o7 h/ @; L
-
% p& J, Y1 N4 s0 B- L - // older versions of IE
1 Z. [4 g0 c6 j7 Q: q. p: u6 B - 7 s4 @) s0 z! i- C- N4 p/ w
- else; P: r3 ^, K- f9 u9 R( r* A/ n
- {: B! H6 ?4 O3 n; i* i; x
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,# S! Q( a0 M1 c1 t1 c
- viewportheight = document.getElementsByTagName('body')[0].clientHeight: ^# y/ r4 g0 ]
- }, ]9 Q( e* G9 V4 s1 \ p; \. |
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
5 G9 c, z, B E. x: P! I- f% A2 R$ L& K - //-->
( W4 V) q+ \( y# F h5 z- I - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯9 U2 ]: X( H: z+ Q
4 N7 k# W8 O' G+ U: I' R/ N6 Y/ b6 M3 f$ h B: a1 O+ w
靘皞: Get viewport size (width and height) with javascript* o8 ~: P% g! `) |6 l$ F& r1 P. z& m
9 h! _! x' @* Y. k* z1 u( L
" k3 J7 e' M" p2 Z$ O5 |( P N) A1 V
|
|