52AV手機A片王|52AV.ONE

 找回密碼
 立即註冊
快捷導航
  • 我愛av論壇BBS
  • 手機A片
  • 自拍偷拍外流區
  • 貼圖區
  • 52av裸聊室
  • 中文-中國主播
Yahoo!奇摩搜尋
熱搜: av4u論壇
Google搜尋
熱搜: av4u論壇
     
查看: 5048|回復: 0

[HTML] 取得目前可見視窗內容的尺寸--Javascript

[複製鏈接]
發表於 2014-12-10 17:42:11 | 顯示全部樓層 |閱讀模式
本帖最後由 media 於 2014-12-10 19:08 編輯 + e9 c6 ?0 K7 L  h2 l

5 L; _$ j' N/ v) P8 }. t+ `最近用javascript取視窗的大小時,遇到不同瀏覽器無法偵測或不同的寬高的問題。後來找到下段這段程式碼,當用於點圖放大並顯示於前景中央位置時非常有用。
9 W1 g0 M) H+ E8 V& A8 ^" l& t
  1. <script type="text/javascript">% T' D) ^/ h5 X: e
  2. <!--
    & r- J$ i  \1 a( r9 y/ j
  3. * U. }8 y  l" K* O
  4. var viewportwidth;" Z5 I( X) T  P$ ?2 E/ @
  5. var viewportheight;* t9 z' @; ^- S* \

  6. ) K7 G) S1 M& J6 f" ]
  7. // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
    # K- j8 J) A( f, I7 P
  8. 3 Y( g" O2 W3 `. c
  9. if (typeof window.innerWidth != 'undefined')
    ) h4 q3 x, h) V& f& N3 S
  10. {6 @5 H, a& m6 }7 i( y8 A7 \
  11.       viewportwidth = window.innerWidth,
    9 h. t  w  @' @2 W7 S. C; V1 C
  12.       viewportheight = window.innerHeight! L7 D* b- X/ N* `, R
  13. }
    : l2 `) C, e9 }6 E- z& @& Y# H
  14. ! P. Q! K- V- h* @2 D
  15. // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)& t2 D; h- Q) y5 S- z  Y2 M" e

  16. ; Y3 ?$ M- k9 d$ y4 W( T
  17. else if (typeof document.documentElement != 'undefined'' {- {1 P8 Q5 V: s' {
  18.      && typeof document.documentElement.clientWidth !=$ z$ R" n" y! C* U, }7 x9 R
  19.      'undefined' && document.documentElement.clientWidth != 0)3 ]: A7 k1 W2 ~. k' y5 w7 D0 |2 Y
  20. {
    + H9 u% O1 e& x) {2 U+ i- F( a2 [
  21.        viewportwidth = document.documentElement.clientWidth,
    $ |9 k9 b* y3 W4 j6 x
  22.        viewportheight = document.documentElement.clientHeight( Z$ f) I- E6 v
  23. }9 E" c1 n- b  [7 }6 T7 b' W
  24. " U: h) c8 T1 ^
  25. // older versions of IE
    & H/ N5 ^2 U# p% c4 u& W7 F6 {/ a
  26. : ?; N; L: w1 {3 J' i7 L
  27. else' f; v# A7 Y. R# n0 x* w" B* L, U
  28. {
    ; J1 w3 ]2 P' a( [8 v$ h
  29.        viewportwidth = document.getElementsByTagName('body')[0].clientWidth,3 c, @' r% w3 v3 u
  30.        viewportheight = document.getElementsByTagName('body')[0].clientHeight
    9 @3 C; u$ q7 ~( O. o
  31. }
    5 L# z/ Y) ~0 b) h8 [3 c% j; f5 N
  32. document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');: z* i) ^4 f) y  m/ k0 Q% N
  33. //-->
    ! W# V# I- U& e/ f
  34. </script>
複製代碼
結果: 在google chrome 顯示結果6 L' ^0 A9 ?- i! R( l$ E5 ~
1.png 9 ?( G' g5 L8 A

$ Q# a8 X: @/ n9 H+ N, f來源:
Get viewport size (width and height) with javascript

9 E5 {6 X# D# c6 @7 `
' M. w. j+ M# T4 v

4 v9 d. H6 I. x9 i9 y% y) ^
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

本區塊內容依據『電腦網路內容分級處理辦法』為限制級網站,限定年滿18歲以上或達當地國家法定年齡人士方可進入,且願接受本站各項條款,未滿18歲 謝絕進入瀏覽。為防範未滿18歲之未成年網友瀏覽網路上限制級內容的圖文資訊,建議您可進行網路內容分級組織ICRA分級服務的安裝與設定。 (為還給愛護 本站的網友一個純淨的論壇環境,本站設有管理員)

QQ|小黑屋|手機板|52AV手機A片王

GMT+8, 2026-5-21 07:02 , Processed in 0.008239 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

連絡站長.廣告招商

[email protected] | Telegram:@asa00061     since 2015-01

快速回復 返回頂部 返回列表