砍敺 media 2014-12-10 19:08 蝺刻摩 % }8 O- S2 K, l8 v( P- t5 A, a7 M
, b% L2 h) J: y, g3 n! h餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
% x" \5 J- F" v/ j5 g- <script type="text/javascript">
' d- h7 h# @1 f; @1 F% i7 \ - <!--
& \, l( U" w* O5 R6 w3 a6 h9 J: ?
7 ~% t9 ^9 q- ~1 b3 @1 @! M: o9 E; m- var viewportwidth;
$ G# X* K3 d- B! X5 P - var viewportheight;
7 Y! |; ^ _5 l* |% S - 3 P% _1 U. V/ E: \
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
d& ]4 ?, a3 z4 n8 B - 2 t5 z5 Z- o4 a9 E9 g8 F
- if (typeof window.innerWidth != 'undefined')
z0 R- n2 k" q! b" b- O1 H( b - {. z1 h( e5 B" U, E; B g
- viewportwidth = window.innerWidth,* i* C7 H2 o" @7 ~5 b4 D4 i7 F
- viewportheight = window.innerHeight
) [; q- B3 [( N' T- k4 _ - }
) k. e4 ]% |0 ~/ @3 E+ ^ -
5 \3 E% b+ u, ?$ D - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)5 v. C- ^* f! }* P
- # X% x u* S* R
- else if (typeof document.documentElement != 'undefined'' m/ ~- W$ N- N- n' l
- && typeof document.documentElement.clientWidth !=
, w( T$ h% `& A0 r# R% c% J0 F - 'undefined' && document.documentElement.clientWidth != 0)9 |$ \, E0 Z7 }" a0 H
- {* B0 E0 V, S6 V: S$ P1 |
- viewportwidth = document.documentElement.clientWidth,
, {. F4 W( g8 J$ B" F' Y - viewportheight = document.documentElement.clientHeight3 K3 S% s! X1 Z# r4 L
- }) P5 z% Y1 w5 V" J0 w- i7 i
- 7 @2 j$ n# N9 P/ m7 b4 u
- // older versions of IE2 l( n& ^) i6 f6 d
- 9 K( F* S& z! [+ X, N
- else
% t" v8 g# L: | - {" M8 n) Y* S9 X3 h7 P# [/ b' X. k
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
; n$ L. s; n3 H" |' ?7 R4 v - viewportheight = document.getElementsByTagName('body')[0].clientHeight
: c% }' \) O3 Z - }. E& ]+ `0 L9 V, P% ~( X
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');& Y8 b6 q7 F6 g! }7 w1 t7 f9 x- N
- //-->
3 _% p2 @# R+ ^4 O7 v2 `9 u* _ - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯3 x5 M* o! H% s8 z
# z- U- M7 e4 q" q
4 t2 I' ]- i) s( J8 v靘皞: Get viewport size (width and height) with javascript
- \: w7 W* K& ?' `# s/ y7 q D! b9 a% c: s9 S, r9 X
@' s) V) I3 O" Y. C4 P: L% x
|
|