Steady.js事件处理工具

联合创作 · 2023-09-22

Steady.js 可实现无闪烁的 onscroll 事件处理,而不会有性能方面的损失。

基本使用方法:

<!DOCTYPE html>
<html>
<head>
  <title>Hello world!</title>
</head>
<body>

  <!-- some HTML things here -->
  
  <script type="text/javascript" src="Steady.js"></script>
  <script>
    var s = new Steady({
      conditions: {
        "width": 400px,
        "scrollX": 0,
        "max-bottom": 200px
      },
      throttle: 100,
      handler: fn
    });
  
    // you cann conditions on the fly!
    s.addCondition('scrollX', 0);
  
    function fn(values, done) {
      var xhr = new XMLHttpRequest();
  
      xhr.open('GET', 'imgs.html');
      xhr.onreadystatechange = function() {
        if ( xhr.readyState == 4 ) {
          document.body.innerHTML += xhr.response;
          
          // telling Steady that we're done processing!
          done();
        }
      };
  
      xhr.send();
    }
  
  </script>
</body>
</html>
浏览 10
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报