pageYOffset 屬性的作用是什麼?
如果你想從左上角視窗開始獲取文件的滾動畫素,那麼需要使用pageXoffset和pageYoffset屬性。對垂直畫素使用pageYoffset。
示例
你可以嘗試執行以下程式碼來學習如何使用JavaScript中的pageYOffset屬性。
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-color: green;
height: 1500px;
width: 1500px;
}
</style>
</head>
<body>
<script>
function scrollFunc() {
window.scrollBy(200, 200);
alert("Vertical: " + window.pageYOffset);
}
</script>
<button onclick="scrollFunc()" style="position:fixed;">Scroll</button>
<br><br><br>
<div>
</div>
</body>
</html>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
Javascript
PHP