>本文展示了一种巧妙的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中文网其他相关文章!