screenLeft只讀屬性返回從用戶瀏覽器窗口的左邊框到屏幕左側(cè)的水平距離(以像素為單位)。
screenLeft屬性是舊版screenX屬性的別名。
window.screenLeft
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屬性。
表格中的數(shù)字指定了完全支持screenLeft屬性的第一個瀏覽器版本:
屬性 | ![]() | ![]() | ![]() | ![]() | ![]() |
screenLeft | 是 | 64 | 是 | 是 | 9 |
返回值: | 此數(shù)字等于從瀏覽器視口的左邊緣到屏幕左邊緣的CSS像素數(shù) |
---|
返回相對于屏幕的新窗口的x和y坐標(biāo):
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.screenTop屬性
窗口(Window)參考:window.screenX屬性
窗口(Window)參考:window.screenY屬性