APP下载
报价宝  ›  科技  › 

web前端开发常用上拉重新整理demo 程式码可直接执行

报价宝 来源:baojiabao.com 发布时间:2019-09-23 16:10:00 10月13日更新
报价宝综合消息web前端开发常用上拉重新整理demo 程式码可直接执行

前端开发过程中常用的上拉重新整理demo,下拉重新整理与此原理类似

界面如下(有点丑的demo哈):

程式码如下如示:

*{

padding: 0;

margin: 0;

}

.box{

height: 100%;

/* overflow: hidden auto; */

}

#refreshContainer{

width: 90%;

margin: 0 auto;

}

ul li{

outline-style: none;

outline: none;

}

#refreshContainer li{

height: 60px;

line-height: 60px;

padding: 0 10px;

background: green;

margin: 10px auto;

list-style:none;

}

111

222

333

444

555

111

222

333

444

555

(function(window) {

// 获取当前滚动条的位置

function getScrollTop() {

var scrollTop = 0;

if (document.documentElement && document.documentElement.scrollTop) {

scrollTop = document.documentElement.scrollTop;

} else if (document.body) {

scrollTop = document.body.scrollTop;

}

return scrollTop;

}

// 获取当前可视范围的高度

function getClientHeight() {

var clientHeight = 0;

if (document.body.clientHeight && document.documentElement.clientHeight) {

clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);

}

else {

clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);

}

return clientHeight;

}

// 获取文件完整的高度

function getScrollHeight() {

return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);

}

var _text = document.querySelector('.refreshText'),

_container = document.getElementById('refreshContainer');

// 节流函式

var throttle = function(method, context){

clearTimeout(method.tId);

method.tId = setTimeout(function(){

method.call(context);

}, 300);

}

function fetchData() {

setTimeout(function() {

_container.insertAdjacentHTML('beforeend', '

new add...'); }, 1000);

}

window.onscroll = function() {

if (getScrollTop() + getClientHeight() == getScrollHeight()) {

_text.innerText = '载入中...';

throttle(fetchData);

}

};

})(window);

程式码可直接复制

每日一分享,感谢所有关注的粉丝们

文章标签: 报价宝 降噪耳机价格 耳机价格 红米手机价格 华为手机价格 小米手机价格 电视机价格 笔记本电脑价格 笔记本价格 汽车价格 报价宝 数码相机价格 手机价格 小米手机价格 耳机价格