screenTop只读属性返回从用户浏览器视口的顶部边框到屏幕顶部的垂直距离(以像素为单位)。
screenTop属性是旧的screenY属性的别名。
window.screenTop
var win = window.open("", "popupWindow"); win.document.write("<p>This is 'popupWindow'"); win.document.write("<br>ScreenLeft: " + win.screenLeft); win.document.write("<br>ScreenTop: " + win.screenTop + "</p>");测试看看‹/›
注意: screenLeft和screenTop属性等于screenX和screenY属性。
表格中的数字指定了完全支持screenTop属性的第一个浏览器版本:
属性 | |||||
screenTop | 是 | 64 | 是 | 是 | 9 |
返回值: | 从浏览器视口的顶部边缘到屏幕顶部的CSS像素数 |
---|
返回相对于屏幕的新窗口的x和y坐标:
var win = window.open("", "popupWindow", "left=500, top=350, width=300, height=200"); win.document.write("<p>This is 'popupWindow'"); win.document.write("<br>ScreenLeft: " + win.screenLeft); win.document.write("<br>ScreenTop: " + win.screenTop + "</p>");测试看看‹/›
跨浏览器解决方案(对于IE8和更早版本,使用screenX和screenY):
var win = window.open("", "popupWindow", "left=500, top=350, width=300, height=200"); /* 如果浏览器不支持screenLeft和screenTop,可以使用screenX和screenY */ if (!window.screenLeft) { window.screenLeft = window.screenX; window.screenTop = window.screenY; } win.document.write("<p>This is 'popupWindow'"); win.document.write("<br>ScreenLeft: " + win.screenLeft); win.document.write("<br>ScreenTop: " + win.screenTop + "</p>");测试看看‹/›
窗口(Window)参考:window.screenLeft属性
窗口(Window)参考:window.screenX属性
窗口(Window)参考:window.screenY属性