Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

GlobalEventHandlers.onscroll

元素的 scroll 事件处理函数。

语法

element.onscroll = functionReference

参数

functionReference 是一个函数的引用。当该元素滚动时,会执行该函数。

示例

<!DOCTYPE html>
<html lang="en">
  <head>
  <meta charset="UTF-8" />
  <style>
  #container {
    position: absolute;
    height: auto;
    top: 0;
    bottom: 0;
    width: auto;
    left: 0;
    right: 0;
    overflow: auto;
  }

  #foo {
    height:1000px;
    width:1000px;
    background-color: #777;
    display: block;
  }

  </style>
  </head>
  <body>
    <div id="container">
      <div id="foo"></div>
    </div>

    <script type="text/javascript">
      document.getElementById('container').onscroll = function() {
        console.log("scrolling");
      };
    </script>
  </body>
</html>

注意

当用户滚动某个元素的内容时 scroll 事件将会被触发。Element.onscroll 同等于 element.addEventListener("scroll" ... )。

规范

Specification Status Comment
Document Object Model (DOM) Level 3 Events Specification
onscroll
Working Draft Initial definition

文档标签和贡献者

标签: 
 此页面的贡献者: Ende93, teoli, jsx, ziyunfei
 最后编辑者: Ende93,