主要记录在ios浏览器出现触摸无限加载的情况

使用vue-scroller和mescroll.js/mescroll.vue先踩ios浏览器默认滑动会影响mescroll的方法调用。

首先给公共js加入以下代码禁用我们的页面在ios浏览器下会滑动上下页面。

<script>
//禁止ios手机双击放大以及缩小
window.onload = function () {
// 阻止双击放大
var lastTouchEnd = 0;
document.addEventListener('touchstart', function (event) {
if (event.touches.length > 1) {
event.preventDefault();
}
});
document.addEventListener('touchend', function (event) {
var now = (new Date()).getTime();
if (now - lastTouchEnd <= 300) {
event.preventDefault();
}
lastTouchEnd = now;
}, false); // 阻止双指放大
document.addEventListener('gesturestart', function (event) {
event.preventDefault();
}); //在ios浏览器调试的时候禁止页面滚动
var ios = navigator.userAgent.indexOf('iPhone');//判断是否为ios
if (ios != -1) {
//ios下运行
var scroll = document.getElementById("scroll")//你需要滑动的dom元素
touchScroll(scroll);
} var canScroll = true;
function touchScroll(el) {
canScroll = false;
//el需要滑动的元素
el.addEventListener('touchmove', function (e) {
canScroll = true;
})
document.body.addEventListener('touchmove', function (e) {
// alert(canScroll);
if (!canScroll) {
e.preventDefault(); //阻止默认事件(上下滑动)
} else {
//需要滑动的区域
var top = el.scrollTop; //对象最顶端和窗口最顶端之间的距离
var scrollH = el.scrollHeight; //含滚动内容的元素大小
var offsetH = el.offsetHeight; //网页可见区域高
var cScroll = top + offsetH; //当前滚动的距离 //被滑动到最上方和最下方的时候
if (top == 0) {
top = 1; //0~1之间的小数会被当成0
} else if (cScroll === scrollH) {
el.scrollTop = top - 0.1;
}
}
}, { passive: false }) //passive防止阻止默认事件不生效
}
} </script>
 
 
 
下面给body设置样式:
 
html,
body {
height: 100%;
width: 100%;
position: fixed;
top: 0;
left: 0;
}
 
接下来就是vue页面使用vue-scroller或者mescroll.js/mescroll.vue;
 
mescroll.js
 
 
<template>
<div class="bg-box">
<div id="mescroll" class="mescroll">
<div>
<mescroll-vue ref="mescroll" :down="mescrollDown" :up="mescrollUp" @init="mescrollInit" class="scrollView">
<div class="invoiceList">
<div v-for="(item,index) in invoiceList" class="invoiceList-box" :key="index">
<a :class="item.isShow?'items-selected':'items'" @click="onItemClick(item,index)"></a>
<div class="information">
<p class="numvber">单号:{{item.OrderNo}}</p>
<p><span class="icon1"></span>始发地 ———— 目的地</p>
<p><span class="icon2"></span>件数 : {{item.Pse}}件</p>
<p><span class="icon2"></span>重量 : {{item.Weight}}KG</p>
<p class="invoicedate">{{item.DownOrderTime}}</p>
</div>
<p class="price">¥{{item.TotalMoney}}</p>
</div>
</div>
</mescroll-vue>
</div>
</div>
</div>
</template> <script>
import MescrollVue from "mescroll.js/mescroll.vue";
export default {
components: {
MescrollVue
},
data() {
return {
mescroll: null, // mescroll实例对象
mescrollDown: {}, //下拉刷新的配置. (如果下拉刷新和上拉加载处理的逻辑是一样的,则mescrollDown可不用写了)
mescrollUp: {
// 上拉加载的配置.
callback: this.upCallback, // 上拉回调,此处简写; 相当于 callback: function(page, mescroll) { }
//以下是一些常用的配置,当然不写也可以的.
page: {
num: 0, //当前页 默认0,回调之前会加1; 即callback(page)会从1开始
size: 5 //每页数据条数,默认10
},
noMoreSize: 5, //如果列表已无数据,可设置列表的总数量要大于5才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看
toTop: {
//回到顶部按钮
src: "./static/mescroll/mescroll-totop.png", //图片路径,默认null,支持网络图
offset: 1000 //列表滚动1000px才显示回到顶部按钮
},
htmlContent:
'<p class="downwarp-progress"></p><p class="downwarp-tip">下拉刷新 </p>', //布局内容
empty: {
//列表第一页无任何数据时,显示的空提示布局; 需配置warpId才显示
warpId: "xxid", //父布局的id (1.3.5版本支持传入dom元素)
icon: "./static/mescroll/mescroll-empty.png", //图标,默认null,支持网络图
tip: "暂无相关数据~" //提示
}
}
};
},
beforeRouteEnter(to, from, next) {
// 如果没有配置回到顶部按钮或isBounce,则beforeRouteEnter不用写
next(vm => {
vm.$refs.mescroll.beforeRouteEnter(); // 进入路由时,滚动到原来的列表位置,恢复回到顶部按钮和isBounce的配置
});
},
beforeRouteLeave(to, from, next) {
// 如果没有配置回到顶部按钮或isBounce,则beforeRouteLeave不用写
this.$refs.mescroll.beforeRouteLeave(); // 退出路由时,记录列表滚动的位置,隐藏回到顶部按钮和isBounce的配置
next();
},
methods: {
mescrollInit(mescroll) {
this.mescroll = mescroll;
},
upCallback(page, mescroll) {
let data = {};
data.uId = 1;
data.type = 10;
data.pageIndex = page.num;
data.pageSize = page.size;
let str = `uId=${data.uId}&type=${data.type}&pageIndex=${
data.pageIndex
}&pageSize=${data.pageSize}`;
this.$http.get(str) //地址换成自己的
.then(res => {
if (res && res.Total > 0) {
if (page.num == 1) {
this.invoiceList = [];
}
this.invoiceList = this.invoiceList.concat(res.DataList);
this.invoiceList.map(item => {
this.$set(item, "isShow", false);
});
this.$nextTick(() => {
mescroll.endSuccess(res.DataList.length);
});
}
})
.catch(e => {
mescroll.endErr();
});
}
}
};
</script>
<style lang="less" scoped>
.mescroll {
position: absolute;
width: 100%;
height: 100%;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: #eee;
overflow: auto;
-webkit-overflow-scrolling: touch;
.mescroll {
position: fixed;
top: 0;
bottom: 0;
height: auto;
}
}
</style>
 
效果

vue-scroller(在main.js引入就不需要再引入了)
 
附代码:
 
 
<template>
<div>
<div class="content">
<div class="content-box">
<scroller :on-refresh="refresh" :on-infinite="infinite" ref="scrollerBottom" refresh-layer-color="#4b8bf4" loading-layer-color="#ec4949">
<!-- 上拉刷新动画 -->
<svg class="spinner" style="stroke: #4b8bf4;" slot="refresh-spinner" viewBox="0 0 64 64">
<g stroke-width="7" stroke-linecap="round">
<line x1="10" x2="10" y1="27.3836" y2="36.4931">
<animate attributeName="y1" dur="750ms" values="16;18;28;18;16;16" repeatCount="indefinite"></animate>
<animate attributeName="y2" dur="750ms" values="48;46;36;44;48;48" repeatCount="indefinite"></animate>
<animate attributeName="stroke-opacity" dur="750ms" values="1;.4;.5;.8;1;1" repeatCount="indefinite"></animate>
</line>
<line x1="24" x2="24" y1="18.6164" y2="45.3836">
<animate attributeName="y1" dur="750ms" values="16;16;18;28;18;16" repeatCount="indefinite"></animate>
<animate attributeName="y2" dur="750ms" values="48;48;46;36;44;48" repeatCount="indefinite"></animate>
<animate attributeName="stroke-opacity" dur="750ms" values="1;1;.4;.5;.8;1" repeatCount="indefinite"></animate>
</line>
<line x1="38" x2="38" y1="16.1233" y2="47.8767">
<animate attributeName="y1" dur="750ms" values="18;16;16;18;28;18" repeatCount="indefinite"></animate>
<animate attributeName="y2" dur="750ms" values="44;48;48;46;36;44" repeatCount="indefinite"></animate>
<animate attributeName="stroke-opacity" dur="750ms" values=".8;1;1;.4;.5;.8" repeatCount="indefinite"></animate>
</line>
<line x1="52" x2="52" y1="16" y2="48">
<animate attributeName="y1" dur="750ms" values="28;18;16;16;18;28" repeatCount="indefinite"></animate>
<animate attributeName="y2" dur="750ms" values="36;44;48;48;46;36" repeatCount="indefinite"></animate>
<animate attributeName="stroke-opacity" dur="750ms" values=".5;.8;1;1;.4;.5" repeatCount="indefinite"></animate>
</line>
</g>
</svg>
<div class="invoiceList">
<div v-for="(item,index) in invoiceList" class="invoiceList-box" @click="InvoiceDetails(item)" :key="index">
<div class="slecets">
</div>
<div class="information">
<p class="numvber">单号:{{item.OrderNo}}</p>
<p><span class="icon1"></span>始发地 ———— 目的地</p>
<p><span class="icon2"></span>件数 : {{item.Pse}}件</p>
<p><span class="icon2"></span>重量 : {{item.Weight}}KG</p>
<p class="invoicedate">{{item.DownOrderTime}}</p>
</div>
<p class="bitch">已开发票</p>
<p class="price">¥{{item.TotalMoney}}</p>
</div>
</div>
<!-- 下拉加载动画 -->
<svg class="spinner" style="fill: #ec4949;" slot="infinite-spinner" viewBox="0 0 64 64">
<g>
<circle cx="16" cy="32" stroke-width="0" r="3">
<animate attributeName="fill-opacity" dur="750ms" values=".5;.6;.8;1;.8;.6;.5;.5" repeatCount="indefinite"></animate>
<animate attributeName="r" dur="750ms" values="3;3;4;5;6;5;4;3" repeatCount="indefinite"></animate>
</circle>
<circle cx="32" cy="32" stroke-width="0" r="3.09351">
<animate attributeName="fill-opacity" dur="750ms" values=".5;.5;.6;.8;1;.8;.6;.5" repeatCount="indefinite"></animate>
<animate attributeName="r" dur="750ms" values="4;3;3;4;5;6;5;4" repeatCount="indefinite"></animate>
</circle>
<circle cx="48" cy="32" stroke-width="0" r="4.09351">
<animate attributeName="fill-opacity" dur="750ms" values=".6;.5;.5;.6;.8;1;.8;.6" repeatCount="indefinite"></animate>
<animate attributeName="r" dur="750ms" values="5;4;3;3;4;5;6;5" repeatCount="indefinite"></animate>
</circle>
</g>
</svg>
</scroller>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
invoiceList: [],
pageIndex: 0,
pageSize: 5,
noDate: false
};
},
mounted() {},
methods: {
//获取开票历史列表
InvoiceList(offset, fn) {
let data = {};
data.uId = 1;
data.type = 20;
data.pageIndex = offset;
data.pageSize = this.pageSize;
let str = `uId=${data.uId}&type=${data.type}&pageIndex=${
data.pageIndex
}&pageSize=${data.pageSize}`;
this.$http.get(str).then(res => { //一样换成自己的接口
if (res && res.Total > 0) {
let maxNum = Math.ceil(res.Total / data.pageSize); //判断总共有多少页 if (offset > maxNum) {
//如果当前页大于总页数判断显示没有更多数据
fn(true);
return;
} else {
if (fn) {
fn();
}
}
if (this.pageIndex == 1) {
this.invoiceList = res.DataList;
} else {
this.invoiceList = this.invoiceList.concat(res.DataList);
}
}
});
},
//下拉刷新
refresh(done) {
this.pageIndex = 1;
setTimeout(() => {
this.InvoiceList(1, done);
}, 1500);
},
//上拉加载数据
infinite(done) {
setTimeout(() => {
this.pageIndex++;
this.InvoiceList(this.pageIndex, done);
}, 1500);
}
}
};
</script>
<style lang="less" scoped>
@import "../../main.less";
.content {
text-align: center;
height: 100%;
overflow: hidden;
.content-box {
position: absolute;
width: 100%;
top: 3.14rem;
bottom: 0;
left: 0;
right: 0;
background: #eee;
}
}
</style>
 

 
安装教程我就不贴了,自行百度。。。
 
踩坑之路。莫喷。。。。
 
 

ios浏览器调试踩坑(1)----mescroll.js和vue-scroller的更多相关文章

  1. React-Native 真机调试踩坑指南

    继上一篇基础安装踩坑继续我们的踩坑之旅,备注一下以下仅针对Mac环境-- 安卓 1.adb 找不到命令? Adb的全称为Android Debug Bridge,就是起到调试桥的作用,真机调试安卓必备 ...

  2. Android NDK中的C++调试踩坑标记

    RT, Android NDK中的C++调试, GDB调试比较麻烦,在ADT Eclipse中: 1.配置好NDK给工程加上Native Support 2.编译中加上NDK_DEBUG=1 3.然后 ...

  3. JS014. toFixed( )调试踩坑 - 浏览器思维 点常量 & 点运算符

    Number.prototype.toFixed( ) 在观察toFixed()丢失精度问题,和对toFixed()方法重写的调试过程时,发现toFixed()对Number的识别有它自己的规则,并找 ...

  4. LoRaWAN调试踩坑心得(一)

    先说两句 在调试和移植的过程中 我们经常想用节点去抓上行包 或者去抓下行包 但在抓取的过程中发现,上行包抓取不到到,或是下行包抓取不到,或者是两个都抓取不到,觉得非常的诡异.明明接收频点.BW和SF都 ...

  5. LoRaWAN调试踩坑心得(二)

    先说两句 抱歉,由于工作原因和个人原因,中间停更了这么久.接下来,本人会继续往下更,内容包括但不仅限于LoRa.文章还是会按照个人的习惯,坚持原创,一是作为自己的笔记,二是和广大工程师分享交流. Lo ...

  6. axios踩坑记录+拦截器使用+vue cli代理跨域proxy+webpack打包部署到服务器

    1.小小的提一下vue cli脚手架前端调后端数据接口时候的本地代理跨域问题,如我在本地localhost访问接口http://40.00.100.100:3002/是要跨域的,相当于浏览器设置了一道 ...

  7. Vue踩坑第一步,安装Vue最新版本

    学习vue第一步肯定是安装vue-cli,那么肯定想去搜下如何安装vue-cli呢? 网上搜到的结果大都是: npm i vue-cli -g 输入vue -V发现: 输入node -v发现: 自己明 ...

  8. html2canvas截屏在H5微信移动端踩坑,ios和安卓均可显示

    1.最近在做移动端开发,框架是vue,一产品需求是,后台返回数据,通过qrcode.js(代码比较简单,百度上已经很多了)生成二维码,然后通过html2canvas,将html元素转化为canvas, ...

  9. C# -- HttpWebRequest 和 HttpWebResponse 的使用 C#编写扫雷游戏 使用IIS调试ASP.NET网站程序 WCF入门教程 ASP.Net Core开发(踩坑)指南 ASP.Net Core Razor+AdminLTE 小试牛刀 webservice创建、部署和调用 .net接收post请求并把数据转为字典格式

    C# -- HttpWebRequest 和 HttpWebResponse 的使用 C# -- HttpWebRequest 和 HttpWebResponse 的使用 结合使用HttpWebReq ...

随机推荐

  1. HttpClient的使用今天遇到一个巨坑——HttpEntity内容取不出来

    在使用HttpPost httpPost = new HttpPost(postUrl);的post请求后,拿到返回的response,response返回200成功. 到此没有任何问题. respo ...

  2. Django 的admin

    admin使用 Django 自动管理工具是 django.contrib 的一部分.你可以在项目的 settings.py 中的 INSTALLED_APPS 看到它: # Application ...

  3. Linux 解决Deepin深度系统无法在root用户启动Google Chrome浏览器的问题

    解决Deepin无法在root用户启动Google Chrome浏览器的问题,步骤如下. 前提:如何用root用户登录系统?编辑 vim /etc/lightdm/lightdm.conf , 找到并 ...

  4. Centos 7 LAMP+wordpress

    一.简介        LAMP--->Linux(OS).Apache(http服务器),MySQL(有时也指MariaDB,数据库) 和PHP的第一个字母,一般用来建立web应用平台. 它是 ...

  5. c# WF 第3节 窗体的属性

    本节内容: 1:如何找到窗口属性 2:窗口属性 1:如何找到窗口属性 2:窗口属性

  6. 201271050130-滕江南《面向对象程序设计(java)》第十周学习总结

    项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...

  7. pytroch 权重初始化和加载词向量的方法

    1.几种不同的初始化方法 import torch.nn as nn embedding = torch.Tensor(3, 5) #如下6种初始化方法 #正态分布 nn.init.normal_(e ...

  8. [C2P3] Andrew Ng - Machine Learning

    ##Advice for Applying Machine Learning Applying machine learning in practice is not always straightf ...

  9. JavaScript 看不见的类型转换

    本章是我阅读JavaScript权威指南时着重留意的内容,同时也推荐正在学习前端的小伙伴可以留意一下这本书<JavaScript权威指南> JavaScript可以很灵活的将一种类型的值转 ...

  10. Linux上发布E卡通项目

    Linux上发布E卡通项目 使用的命令 ps -ef | grep java kill -9 22314 nohup java -jar smartcard-ms-0.0.1-SNAPSHOT.jar ...