美文网首页
加载更多。。。

加载更多。。。

作者: 罗小耳 | 来源:发表于2017-08-08 20:08 被阅读55次

》写在前面:自己留个记号,仅供自己使用,如想实现类似的,可以参考

一、wap端
1、首先来个weui.css
2、写上下面一块css

.page__bd {
    width: 100%;
}

3、html

<ul class="custom-list">

            <c:forEach items="${models}" var="model">

                <li class="clearFix"><c:choose>
                        <c:when test="${empty model.avatar and empty model.phone}">
                            <div>
                                <div>
                                    ![用户头像](https://img.haomeiwen.com/i1076687/0f674dc073d0954a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
                                </div>
                            </div>
                        </c:when>
                        <c:when test="${empty model.avatar  and not empty model.phone }">
                            <div>
                                <div>
                                    ![用户头像](https://img.haomeiwen.com/i1076687/a2bf5fbc89c3e35d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
                                </div>
                            </div>
                        </c:when>
                        <c:otherwise>
                            <div>
                                ![](${model.avatar})
                            </div>
                        </c:otherwise>
                    </c:choose>

                    <ul>

4、js

$(function() {
        // 监听滚动条
        $(window).scroll(BottomJumpPage);

        $(window).load(function() {
            var scrollTop = $(this).scrollTop();
            var scrollHeight = $(document).height();
            var windowHeight = $(this).height();
            /* 判断页面初始时是否有数据 */
            var customListHeight = $(".custom-list").height();
            if (customListHeight == 0 || customListHeight < windowHeight-58) {
                $(".page__bd").hide();
            }
        });

    });

    // 判断是否到达底部
    function BottomJumpPage() {
        var scrollTop = $(this).scrollTop();
        var scrollHeight = $(document).height();
        var windowHeight = $(this).height();
        console.dir("scrollTop" + scrollTop);
        console.dir(scrollHeight);
        console.dir(windowHeight);
        if (scrollTop + windowHeight == scrollHeight) { //滚动到底部执行事件
            console.dir("我到底部了"); 
            //$(".custom-list").append(getOrderHtml("df"));
            var pageIndex = parseInt($("#pageIndex").val()) + 1;
            $.getJSON("/distribution/user/list?pageIndex=" + pageIndex,
                    function(data) {
                        if (data.list.length < 15) {
                            $(".page__bd").hide();
                        } else {
                            $(".page__bd").show();
                        }
                        $.each(data.list, function(index, user) {
                            console.log(pageIndex);
                            $("#pageIndex").val(data.pageIndex);
                            var html = getOrderHtml(user);
                            $(".custom-list").append(html);
                        });
                    });
        }
        if (scrollTop == 0) { //滚动到头部部执行事件
            console.dir("我到头部了");
        }
    };

    function getOrderHtml(user) {
        var html = [];
        html.push('<li class="clearFix">');

        html.push('<div>');

        if(user.avatar==""||user.avatar==undefined||user.avatar==user){
            if(user.phone==""||user.phone==undefined||user.phone==user){
                html.push('![用户头像](https://img.haomeiwen.com/i1076687/0f674dc073d0954a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)');
            }else{
                html.push('![用户头像](https://img.haomeiwen.com/i1076687/a2bf5fbc89c3e35d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)');
            }

        } else {
            html.push('![]('+user.avatar+')');
        }

        html.push('</div>');

        html.push('<ul>');
        if (user.nickname == "") {
            html.push('<li>客户:【匿名】</li>');
        } else {
            html.push('<li>客户:' + user.nickname + '</li>');
        }

        html.push('<li>&nbsp</li>');
        html.push('<li>手机:' + user.phone + '</li>');
        html.push('<li>访问IP:******</li>');
        html.push('<li>地址:北京市*****</li>');
        html.push('<li>注册时间:' + new Date(user.createTime).format("yyyy-MM-dd")
                + ' </li>');
        html.push('</ul>');

        html.push('</li>');

        return html.join("");
    }

二、固定高度的div加载更多
1、css

.commonInputBorderBox {
    min-height: 150px;
    border: 1px solid #95989A;
    height: 500px;
    position: relative;
}

2、html

<div class="floatl commonInputHuiBtnBox commonInputBtnBox">

                        <div class="right-o-list-goodsMsg-imgMsg"> 
                            <img alt="" src="" class="floatl">
                            <div class="floatl">
                                <div>小黄人蛋糕</div>
                                <div>X 1 (个)</div> 
                                <div>¥:1001.00</div>
                            </div>
                        </div>
                        <div class="right-o-list-goodsMsg-imgMsg">   
                            <img alt="" src="" class="floatl">
                            <div class="floatl">
                                <div>小黄人蛋糕</div>
                                <div>X 1 (个)</div>
                                <div>¥:1001.00</div>
                            </div>
                        </div>
                    </div>

3、js

var scrollItem = document.getElementById("goodsListBox");
scrollItem.onscroll = scrollHandle;
// 监听商品列表滚动
function scrollHandle() {
    var wholeHeight = scrollItem.scrollHeight;
    var scrollTop = scrollItem.scrollTop;
    var divHeight = scrollItem.clientHeight;
    if (divHeight + scrollTop >= wholeHeight) {
        console.log("已经到达底部");
        // 加载数据
        loadProductListData();
    }
}

相关文章

  • 加载更多。。。

    》写在前面:自己留个记号,仅供自己使用,如想实现类似的,可以参考 一、wap端1、首先来个weui.css2、写上...

  • 加载更多

    html代码 server-mock模拟后端代码 【个人总结,如有错漏,欢迎指出】:>

  • 加载更多

    12个加载更多。 大约还要10个。 才能下载完你的文章。 微信打开链接,然后点击加载更多,中指滚动下拉,数数,打开...

  • React Native刷新加载更多

    react native的刷新加载更多,有多种方案 "加载更多" 需要点击 "加载更多" 根据手势向上滑动,自动显...

  • 需求分析:加载更多

    Part.One 功能概述 功能名称 加载更多 功能描述 点击“加载更多”按钮、或上拉列表时,加载更多的内容。 使...

  • thinkphp3.2.3的ajax加载更多

    效果:点击加载更多,根据设定的加载条数显示加载内容,全部加载完毕后加载更多按钮消失。话不多说,直接上代码。 htm...

  • 点击加载更多

  • js 加载更多

  • 拉下加载更多

    componentDidMount(){ //获取列表数据 this.getListData(); // 下...

  • 加载更多特效

    1.有些时候,首页加载更多的按钮不需要用到ajax,通过特效展现,每次点击展示两行内容。多余内容隐藏掉。 html...

网友评论

      本文标题:加载更多。。。

      本文链接:https://www.haomeiwen.com/subject/ipdxrxtx.html