`
ipython
  • 浏览: 289219 次
  • 性别: Icon_minigender_1
  • 来自: 佛山
社区版块
存档分类
最新评论

javascript 向下滚动

    博客分类:
  • web
web 
阅读更多

Google Reader 阅读器中,当向下拉动到尾部时,它会自动加载下面的部分。

下面的代码主要实现的是向下滚动。

 

<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>无限滚动</title>
    <style type="text/css" media="screen">
        ul {width:200px; height:100px; overflow-y:auto;}
    </style>
</head>
<body>
    <ul id="x">
        <li>hello</li>
        <li>hello</li>
        <li>hello</li>
        <li>hello</li>
        <li>hello</li>
        <li>hello</li>
        <li>hello</li>
        <li>hello</li>
    </ul>
    <script type="text/javascript" charset="utf-8">
        var i = 0;
        var $ = function (name) {return document.getElementById(name) };
        var a = $('x');
        a.onscroll = function () {
            if ( this.scrollHeight - this.clientHeight - this.scrollTop < 10) {
                console.log (i);
                var li = document.createElement('li');
                li.innerHTML = "hello " + i++;
                this.appendChild (li);
                if (i >= 40) {
                    this.onscroll = null
                       return;
                }

            }
        }
    </script>
</body>
</html>
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics