>本文展示了一種巧妙的JavaScript解決方案,用於動態調整彈出窗口的大小,以完美適合它們顯示的圖像。 該技術在包括Netscape Navigator 4/5/6/7和Internet Explorer 4/5/6的各種瀏覽器上工作
)。 popup.htm
>
,通過查詢字符串傳遞圖像URL:PopupPic()
popup.htm
>
function PopupPic(sPicURL) { window.open("popup.htm?" + sPicURL, "", "resizable=1,HEIGHT=200,WIDTH=200"); }
>事件來調用圖像加載後popup.htm
函數:<img alt="調整彈出窗口的大小以適合圖像的大小" >
document.write()
onload
FitPic()
函數計算圖像尺寸和瀏覽器窗口尺寸之間的差異。 然後,它使用
var arrTemp = self.location.href.split("?"); var picUrl = (arrTemp.length > 1) ? arrTemp[1] : ""; var NS = (navigator.appName == "Netscape") ? true : false; function FitPic() { var iWidth = (NS) ? window.innerWidth : document.body.clientWidth; var iHeight = (NS) ? window.innerHeight : document.body.clientHeight; iWidth = document.images[0].width - iWidth; iHeight = document.images[0].height - iHeight; window.resizeBy(iWidth, iHeight); self.focus(); }; document.write("<img src="%22%20+%20picUrl%20+%20%22" border="0" alt="調整彈出窗口的大小以適合圖像的大小" >");
FitPic()
window.resizeBy()
常見問題(常見問題解答):
>
>>確保彈出式調整大小:>使用JavaScript動態獲取圖像尺寸並相應地設置彈出尺寸。
drawImage
保持簡單,使用清晰的消息傳遞,並使其易於關閉。 smoothingQuality = 'high'
以上是調整彈出窗口的大小以適合圖像的大小的詳細內容。更多資訊請關注PHP中文網其他相關文章!