砍敺 media 2014-12-10 19:08 蝺刻摩
7 X8 U! n5 s( J" z# v- X p- J$ I
1 p* a2 Z$ ?7 L餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
. Q9 q# r" b" P- <script type="text/javascript">& p2 ^7 J& N5 B7 x R+ Y% q/ Z7 O
- <!--6 _. y. L: i+ g# Q3 b) h" o
- ! k. `2 S- q7 M* S2 {
- var viewportwidth;! X2 S. U" o, U1 T' k
- var viewportheight;
{* b; v3 q: r! l% q - . p4 O; V3 |, u& F, e" p! t5 y
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
6 X8 ^: e+ U+ {6 f& y9 o: o - 3 s. i) ^% y0 C3 \* M
- if (typeof window.innerWidth != 'undefined'); \) y e" S' a! ]
- { ^' j; u" w% ~, [3 w1 r5 U
- viewportwidth = window.innerWidth,
8 e4 B. p! ^3 _. j7 \& f! K - viewportheight = window.innerHeight
) U- m5 F+ d( w. F1 I7 N& V/ Z7 e6 ^ - }6 N* U# C8 C1 N- J7 ]
-
" a( r9 K$ O5 ^9 h7 q3 [ - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)8 i8 g% I: P) d! _- R- S! c- Y. E" J
- ' q% r1 g* u6 [* O/ T1 X4 H
- else if (typeof document.documentElement != 'undefined'* v# z' ~$ F5 B/ u+ w
- && typeof document.documentElement.clientWidth !=7 P, Q: M5 T7 ^" f- k
- 'undefined' && document.documentElement.clientWidth != 0), F7 m; W# v8 j( k# C( Z
- {
& [& V' X" u" J8 ]- w4 @ - viewportwidth = document.documentElement.clientWidth,# e) ?! z; b4 A
- viewportheight = document.documentElement.clientHeight
: W/ e' D$ s0 |/ a, b9 e) J4 J# d - }
( d+ t0 L4 J6 s0 n. U% ~/ c/ b -
2 ~+ W. W0 s' j! @ - // older versions of IE1 M% C" L8 y8 x+ _6 z6 a x
- , E0 b/ X8 A3 b$ f/ N
- else3 t( X5 z$ B# v% ?' `4 N5 P8 e0 c
- {2 Q6 u' _7 |9 ^& j: m' o
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
1 R5 B0 p( g0 Q4 R+ I% r - viewportheight = document.getElementsByTagName('body')[0].clientHeight
1 t5 E0 f+ a$ x - }- S- T# m7 U3 m+ H+ g' @
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
+ V0 @& ^ y8 w/ K' F - //-->$ T& w; b1 Y. T) \
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯6 V B6 r( h6 B) A: \- I6 i" y# g
6 }. G- g$ [) J
X a: G# |, K1 ?, t2 P3 n
靘皞: Get viewport size (width and height) with javascript2 @6 n f) X9 x; J7 }
, H( O) t8 [& j! q! d8 p9 \
7 C8 k- U2 e1 @3 m4 g& h
|
|