砍敺 media 2014-12-10 19:08 蝺刻摩 ; D3 }- M A2 ]
2 O! @ t. c- r! Q5 e. q餈甫avascript閬蝒憭批嚗唬閬賢函⊥菜葫銝撖祇憿敺靘曉唬畾菟畾萇撘蝣潘嗥冽潮曉之銝阡*蝷箸澆臭葉憭桐蝵格撣豢具! j( D) T/ h9 K4 Z* e- A
- <script type="text/javascript">
$ G; B( U- e# P7 p - <!--/ I" r& e6 p% G1 `% |" E
- 0 |5 ~$ `# P, ]- }. u/ i1 d
- var viewportwidth;% X1 K- F8 {, `( M" a' E7 m
- var viewportheight;
" j. R1 n$ B8 q8 r; q -
) L( f' T7 A P- t+ a - // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
1 `7 z- J1 A5 ^7 X3 G+ ~% K" C+ ` - 3 s; w) I# ?2 J% ?; }
- if (typeof window.innerWidth != 'undefined')! v; [; w5 r5 [6 K9 C; I1 h
- {- b, ^0 c$ K6 p4 \6 M
- viewportwidth = window.innerWidth,# C% {+ I" W% ]1 Y! b
- viewportheight = window.innerHeight& z+ {: s5 m# z) N" t
- }
2 a# f, ?. o( w3 o. v -
# f+ w+ b. T+ j, o$ v8 A - // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)- v: C; i) }% d1 w) ]2 a
- + X; Q. ]. o6 e
- else if (typeof document.documentElement != 'undefined'
: M2 G& V0 r. J8 X2 X( X3 f - && typeof document.documentElement.clientWidth !=
$ z$ V/ q2 N5 w. f' | - 'undefined' && document.documentElement.clientWidth != 0) ]9 E" X3 D+ r
- {! |0 e3 X, U8 e! }3 j9 T# u+ q* ~
- viewportwidth = document.documentElement.clientWidth,
3 S; o, T( ~1 t4 @0 s2 X# \7 w7 b - viewportheight = document.documentElement.clientHeight
1 O- Q) Z' ?" P) P* H - }
# t9 c q3 V+ V/ I4 L2 Q$ X -
: d# I4 s$ Z6 E8 h- l - // older versions of IE
8 R: r7 s' m2 J! ]2 k; P -
' S" R$ N% M. k( g+ X7 J - else
; ~3 E- T* \+ z; `! ~# N8 U7 ~/ ` - {+ a& F( z: c% f# k! Y# Z6 Z* @) R
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
d8 s5 B- K' e - viewportheight = document.getElementsByTagName('body')[0].clientHeight8 W/ _8 \% e8 j5 {/ r
- }1 i& o6 l2 M! m2 x" L
- document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');7 a/ u$ ]8 g- Y1 j6 G8 d
- //-->- |; V2 ^& e7 \+ Z5 g" X
- </script>
銴鋆賭誨蝣 蝯: 狂oogle chrome 憿舐內蝯1 S. n7 M9 P0 f7 {6 @
+ {& _2 O6 r; z# A
/ |# d# b, D' Z1 ~; |* L
靘皞: Get viewport size (width and height) with javascript9 ~- @4 K8 O& o' a
( k# @7 l ]: S+ K4 w( V+ ?
0 U* s5 M2 x$ m! r" h
|
|