博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
前端画面-下拉后滚动
阅读量:6976 次
发布时间:2019-06-27

本文共 6282 字,大约阅读时间需要 20 分钟。

 

 

前端出现混合模式,一个站点需要手机访问和PC访问,在进行混合模式中,一个分页下拉滚动的功能是需要自己考虑的,这里有两种方法,自己开发和使用插件。为了减少开发复杂难度,插件有:iscroll 和 https://github.com/ximan/dropload,这个都是没有实验过的插件,在进行插件使用的时候,值得注意的点在于,iscroll-probe.js的插件中,有一个参数一定要注意,

//preventDefault: true,

这个参数是将A标签对应的默认事件都去除,使得A标签将会失效,如果你需要将A标签释放出来,那么,这个参数需要修改为false即可,还有一个地方需要注意,如果进行加载的时候,有出现拉下,松手后反弹的情况,那么,将异步加载的方式设置为 

async: false,

效果会更好,所以,在前端的时候值得注意点的是这两个,然后附上前端部分js代码,进行使用,

iScroll demo: simple
Pull down to refresh...
  • Pretty row 1
  • Pretty row 2
  • Pretty row 3
  • Pretty row 4
  • Pretty row 5
  • Pretty row 6
  • Pretty row 7
  • Pretty row 8
  • Pretty row 9
  • Pretty row 10
  • Pretty row 11
  • Pretty row 12
  • Pretty row 13
  • Pretty row 14
  • Pretty row 15
  • Pretty row 16
  • Pretty row 17
  • Pretty row 18
  • Pretty row 19
  • Pretty row 20
  • Pretty row 21
  • Pretty row 22
  • Pretty row 23
  • Pretty row 24
  • Pretty row 25
  • Pretty row 26
  • Pretty row 27
  • Pretty row 28
  • Pretty row 29
  • Pretty row 30
  • Pretty row 31
  • Pretty row 32
  • Pretty row 33
  • Pretty row 34
  • Pretty row 35
  • Pretty row 36
  • Pretty row 37
  • Pretty row 38
  • Pretty row 39
  • Pretty row 40
Pull up to refresh...
View Code

这个是官网的demo:地址view-source:http://cubiq.org/dropbox/iscroll4/examples/pull-to-refresh/

 

主要的js代码片段

var myScroll,    pullDownEl, pullDownOffset,    pullUpEl, pullUpOffset,    generatedCount = 0;function pullDownAction () {    setTimeout(function () {    // <-- Simulate network congestion, remove setTimeout from production!        var el, li, i;        el = document.getElementById('thelist');        for (i=0; i<3; i++) {            li = document.createElement('li');            li.innerText = 'Generated row ' + (++generatedCount);            el.insertBefore(li, el.childNodes[0]);        }                myScroll.refresh();        // Remember to refresh when contents are loaded (ie: on ajax completion)    }, 1000);    // <-- Simulate network congestion, remove setTimeout from production!}function pullUpAction () {    setTimeout(function () {    // <-- Simulate network congestion, remove setTimeout from production!        var el, li, i;        el = document.getElementById('thelist');        for (i=0; i<3; i++) {            li = document.createElement('li');            li.innerText = 'Generated row ' + (++generatedCount);            el.appendChild(li, el.childNodes[0]);        }                myScroll.refresh();        // Remember to refresh when contents are loaded (ie: on ajax completion)    }, 1000);    // <-- Simulate network congestion, remove setTimeout from production!}function loaded() {    pullDownEl = document.getElementById('pullDown');    pullDownOffset = pullDownEl.offsetHeight;    pullUpEl = document.getElementById('pullUp');        pullUpOffset = pullUpEl.offsetHeight;        myScroll = new iScroll('wrapper', {        useTransition: true,        topOffset: pullDownOffset,        onRefresh: function () {            if (pullDownEl.className.match('loading')) {                pullDownEl.className = '';                pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Pull down to refresh...';            } else if (pullUpEl.className.match('loading')) {                pullUpEl.className = '';                pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Pull up to load more...';            }        },        onScrollMove: function () {            if (this.y > 5 && !pullDownEl.className.match('flip')) {                pullDownEl.className = 'flip';                pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Release to refresh...';                this.minScrollY = 0;            } else if (this.y < 5 && pullDownEl.className.match('flip')) {                pullDownEl.className = '';                pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Pull down to refresh...';                this.minScrollY = -pullDownOffset;            } else if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) {                pullUpEl.className = 'flip';                pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Release to refresh...';                this.maxScrollY = this.maxScrollY;            } else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match('flip')) {                pullUpEl.className = '';                pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Pull up to load more...';                this.maxScrollY = pullUpOffset;            }        },        onScrollEnd: function () {            if (pullDownEl.className.match('flip')) {                pullDownEl.className = 'loading';                pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Loading...';                                pullDownAction();    // Execute custom function (ajax call?)            } else if (pullUpEl.className.match('flip')) {                pullUpEl.className = 'loading';                pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Loading...';                                pullUpAction();    // Execute custom function (ajax call?)            }        }    });        setTimeout(function () { document.getElementById('wrapper').style.left = '0'; }, 800);}document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false);
View Code 

使用的时候注意

转载地址:http://gaupl.baihongyu.com/

你可能感兴趣的文章
开启笔记本win7的虚拟热点,让你的本本变成wifi
查看>>
ETL数据抽取策略
查看>>
Python学习day5作业-ATM和购物商城
查看>>
Kubernetes基于Metrics Server的HPA
查看>>
比尔盖茨护犊子 称iPad让大批用户沮丧
查看>>
js 中文匹配正则
查看>>
pkg mysql 在macOS 上的管理
查看>>
将数组A中的内容和数组B中的内容进行交换(数组一样大)
查看>>
Nginx 负载均衡
查看>>
聊聊jesque的几个dao
查看>>
数据结构:二分查找 java
查看>>
docker-dockerfile
查看>>
vmstart的用法
查看>>
linux中安装程序
查看>>
十四周四次课
查看>>
React使用ES6语法重构组件代码
查看>>
标准功能模块组件 -- 内部联络单组件,内部邮件组件,提高多人异地协同办公效率...
查看>>
JEECG社区《微信小程序开发培训》视频
查看>>
软件开发--深入理解程序的结构
查看>>
MongoDB安装
查看>>