砍敺 media 2014-12-10 19:08 蝺刻摩
0 |0 C) p) f; ]2 _6 [4 I% t y& k* T$ N5 o
餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具( `' W/ Z! ~; h* w. |
- <script type="text/javascript">2 _, J7 D: ^+ v J/ ]
- <!--
# m% P# T9 l: d: L
! v& y' N- G( _/ y8 ]' z6 l. q5 N- var viewportwidth;
9 }4 t0 ]4 g& {% b4 t) H6 w# B - var viewportheight;3 ? f) x4 j0 `" Q' |
-
B5 N- q# Q* t, n - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight) I+ F$ |# b" O
-
* E! E7 j8 J; x - if (typeof window.innerWidth != 'undefined')
7 T, d+ q6 B9 e6 h! Z; u - {
; u9 O# K* t; v2 w: h& T0 c - viewportwidth = window.innerWidth,
) U4 a$ Z& K, n5 r - viewportheight = window.innerHeight( f3 }, l- _8 J
- }8 L4 O! Q' j' _& M1 ~" Q
- , P3 \! O6 t8 f, R
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)% Z" U1 m/ F3 G
# \9 a" v g# D# ^. E- else if (typeof document.documentElement != 'undefined'
$ ~* j2 a( }; |, s - && typeof document.documentElement.clientWidth !=
0 B. ]& |" l9 g6 C! K% w& Z5 A. w - 'undefined' && document.documentElement.clientWidth != 0)
( t8 ^. F* D6 y7 P6 g - {
2 v* |7 U( ]8 e2 h - viewportwidth = document.documentElement.clientWidth,, d% ]+ `5 U& v- f4 s8 E
- viewportheight = document.documentElement.clientHeight
6 R1 z$ g6 Z; n' [0 H6 a - }# z4 x' e; w/ g5 n, S
-
8 o) D8 P0 [( t; X; k2 k+ G - // older versions of IE
5 w) X$ F, N. w. B5 ~ - 0 C9 j3 @" A& \/ M5 F* `
- else
/ E" u" Y+ D, N' P - {
7 F% R2 p! R- `; i/ i" F - viewportwidth = document.getElementsByTagName('body')[0].clientWidth,' a, J6 v h' t! R+ s _. M
- viewportheight = document.getElementsByTagName('body')[0].clientHeight1 [) a& F3 F' Y- ?
- }: g4 g8 G( Q; e8 ~1 r1 H$ _( m7 {
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>'); ?+ m) `+ O2 e) `( O" I4 l
- //-->
% m: S( j) Q9 z6 E: b! x2 E) Q - </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯3 Y; S7 \. _7 m- M4 O6 }) U b
/ Q6 t) L! G: `4 w( T: O, | U# S' f' F, q, Q) D+ C
靘皞: Get viewport size (width and height) with javascript
( L. d; ]0 F$ b1 t8 C: L1 K" g. `6 n6 @2 @! S
& h+ d1 z. \8 P: o/ P1 ~) j0 j
|
|