砍敺 media 2014-12-10 19:08 蝺刻摩
L6 w3 s' S/ I0 P4 X
* b2 l# o1 y' ]" _: A餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具) a; T' _; m0 W. S# d7 ^
- <script type="text/javascript"># F0 Q: ~- w$ ?# u- o( D
- <!--
6 t' z8 |5 j+ c$ |) @7 h
0 V0 x) e2 g( v7 r, s- var viewportwidth;* [0 ^$ \- e7 s8 Z, |! K
- var viewportheight;
: y4 b/ N0 C! N0 F - 4 b. Z' p: V# s; N9 c
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight0 ~' U' H$ k& V: r
- 3 j$ {! X/ `" ^+ `% A1 M9 ~
- if (typeof window.innerWidth != 'undefined')
; D2 D+ H/ j% U* T$ e5 A - {3 c: z# |: D% [1 O9 u
- viewportwidth = window.innerWidth,
* y$ G2 U& \0 J1 Z, Q - viewportheight = window.innerHeight2 I& |# ]: G t- E. k
- }# M$ _# W7 m. w
- + ]' M. M( B) j3 K9 G
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)% I9 S1 c- e" J
* u" l0 f) r* X- else if (typeof document.documentElement != 'undefined'
* \. Y: x% Y' r* @( ~$ \ - && typeof document.documentElement.clientWidth !=
# y. G6 a" D! ~2 c- ^$ T* W - 'undefined' && document.documentElement.clientWidth != 0)4 E3 G# J) ^1 ^# U8 |
- {9 i+ y; C, B' n9 q4 l7 J
- viewportwidth = document.documentElement.clientWidth,7 Y. p+ k7 U% k' Q# W! d
- viewportheight = document.documentElement.clientHeight4 @0 h$ t& @3 m) O, \3 q, p% n4 _9 D3 ?
- }
' E+ y+ j) d8 a: b+ Q& y -
( x' H- {1 e# m) F7 y8 [ - // older versions of IE
' _/ J4 O( h. }% ^/ I, j - 3 F7 X/ @% l5 A; @
- else; K5 Z0 d8 l& b/ M# \8 S* F
- {
. ~0 z C/ R5 B9 J0 \6 i - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,# k: F# M) D& a- d* O& w3 X
- viewportheight = document.getElementsByTagName('body')[0].clientHeight
( R7 @) p5 l" l* ]) Z - }5 s7 b& U! \# P8 S2 [8 a
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
# K9 Q6 i0 |% l# q6 K - //-->
_3 ]0 Q1 S& }/ S - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
$ P' u' `$ a; [) s% h7 c
# o0 _ `4 N) W/ y5 N& x
, |1 Z+ {- E! O) w8 ^, ]
靘皞: Get viewport size (width and height) with javascript
7 W7 k ^1 e# ]+ I- x! d; C0 d' I
P1 @' a+ X6 \
|
|