Code Monkey home page Code Monkey logo

Comments (2)

hahnzhu avatar hahnzhu commented on August 16, 2024

具体指的是哪一个组件?

from frozenjs.

fayching avatar fayching commented on August 16, 2024

因为没有固定的结构,这种页面拉到底部继续加载的交互现在一般没有用组件,就是在onscroll事件中判断滚动条高度和页面高度,下面的代码可以参考下:

 function onScroll() {
        if (base.hasMask() || !hasMore) {
            return;
        }
        var viewHeight = $(window).height();//浏览器可视区域高度
        var scrollHeight = $(window).scrollTop();//已滚动高度
        var docHeight = $(document).height();//页面文档高度
        var loadingHeight = $("#loading").height();
        if (lastDocHeight == docHeight) {//避免页面内容改变前多次触发滚动条事件导致重复加载内容
            return false;
        }
        if (viewHeight + scrollHeight >= docHeight - loadingHeight / 2) {
            lastDocHeight = docHeight;
           // to do something
        } else if (viewHeight + scrollHeight >= docHeight - loadingHeight / 2 - 100) {
            var date = new Date();
            var now = date.getTime();
            if (window.lastSetScrollTime == undefined || now - window.lastSetScrollTime >= 200) {
                document.body.scrollTop = scrollHeight;
                window.lastSetScrollTime = now;
            }
        }
    }
      $(window).scroll(function (event) {
            onScroll();
        });

from frozenjs.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.