砍敺 media 2014-12-10 19:08 蝺刻摩 3 Q+ B7 d7 Z- b2 T
: i# b" H6 p1 F+ o3 q1 }餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具
1 |5 ~/ E( Y, n+ I+ e' p- <script type="text/javascript"># e0 ^% Y* n4 u! |. ^" `) s$ m- g
- <!--* M; h3 R7 h, J
* I7 s4 [0 C9 ]& r- var viewportwidth;0 Y7 r/ B# w! A$ A' ]2 i* b
- var viewportheight;
( e/ Q# l$ R- s4 F' \ -
9 B" s3 f# i+ A) k$ O - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
' E0 ~! d5 p2 x8 K* [/ v( o" s8 a -
$ m( x% C$ ]7 n- b9 l0 O. g; A" m1 s6 i - if (typeof window.innerWidth != 'undefined')
& y4 H" |% d$ r' M - {) O) Z2 ] e7 f( O% V5 C6 r
- viewportwidth = window.innerWidth," k# o$ u8 Y0 _7 j8 `$ [* G
- viewportheight = window.innerHeight3 H2 t5 q! M. W7 l% Y2 y
- }8 q ]6 V/ T8 s
-
4 I0 a# d' U5 D# ~7 r$ a) W - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
6 A3 b A" S. K7 S* D7 X
$ s2 V& U+ ]& u) a7 S7 ?0 o( q- else if (typeof document.documentElement != 'undefined'
- y( ?7 Q q# C- Z! N% x - && typeof document.documentElement.clientWidth !=
0 d* ^8 p0 r' M2 {3 H6 r - 'undefined' && document.documentElement.clientWidth != 0)
+ A6 \- z8 @0 T# k) Z# u( ~ - {
9 C" X' d, ~. g9 h/ H4 [ - viewportwidth = document.documentElement.clientWidth,
+ U7 w0 q( ?) u9 N' m5 U - viewportheight = document.documentElement.clientHeight
4 ]. K6 p; I5 [$ C/ \" S - }
2 Q6 D! A- n7 h7 K/ s: A( f - ! v9 Y! f/ t0 p7 Q7 z
- // older versions of IE& [: r" G! s4 n& J' @6 E
-
7 g( ?6 k: H. N, F - else, P/ B+ t m& R6 U, L J5 |# f6 C$ X- k
- { s6 ]+ C& E) y0 ^
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth," H& t/ r6 [6 _
- viewportheight = document.getElementsByTagName('body')[0].clientHeight4 @* {. s' W; ` V
- }
% _ d% P* }$ Z# x0 c - document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
3 @' h1 ~# z' p' r - //-->% J; W5 [ }) P4 x
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯
4 L2 x4 q7 z" Z- C. l
% H* g z1 [/ C" ^9 O9 V5 L
9 ]' q& ?6 H% H靘皞: Get viewport size (width and height) with javascript
/ X# Q/ m& ?/ h! q5 h! b
$ F6 a, ?7 L3 b: m: ^/ t7 q1 `' W% V" Y; a" e9 X
|
|