本文实例为大家分享了vue实现原生下拉刷新的具体代码,供大家参考,具体内容如下
这是动画样式

文字样式

html代码
- <template>
- ? <div class="car-box">
- ? ? <div class="car">下拉刷新</div>
- ? ? <div class="box" @touchstart="fnstart" ref="Element">
- ? ? ? <div class="con-txt">上拉刷新</div>
- ? ? </div>
- ? </div>
- </template>
js代码
- <script>
- export default {
- ? methods: {
- ? ? fnstart(ev) {
- ? ? ? this.$refs["Element"].style.top = 0;
- ? ? ? this.scroolTop =
- ? ? ? ? ev.changedTouches[0].pageY - this.$refs["Element"].offsetTop;
- ?
- ? ? ? document.ontouchmove = this.fnmove;
- ? ? ? document.ontouchend = this.fnEnd;
- ? ? ? ev.preventDefault && ev.preventDefault();
- ? ? },
- ? ? fnmove(ev) {
- ? ? ? ev.target.parentNode.children[0].innerHTML = "下拉刷新";
- ? ? ? this.T = ev.changedTouches[0].pageY - this.scroolTop;
- ? ? ? if (this.scale > 0.12) {
- ? ? ? ? this.scale = 1 - this.T / 200;
- ? ? ? } else {
- ? ? ? ? this.scale = 0.12;
- ? ? ? }
- ? ? ? this.$refs["Element"].style.top = this.T * this.scale + "px";
- ? ? },
- ? ? fnEnd(ev) {
- ? ? ? ev.target.parentNode.children[0].innerHTML = "正在刷新...";
- ? ? ? document.ontouchmove = null;
- ? ? ? document.ontouchend = null;
- ? ? ? setTimeout(() => {
- ? ? ? ? this.$refs["Element"].style.top = 0;
- ? ? ? ? this.$refs["Element"].style.transition = ".3s ease all";
- ? ? ? ? this.$refs["Element"].addEventListener("transitionend", () => {
- ? ? ? ? ? this.$refs["Element"].style.transition = null;
- ? ? ? ? });
- ? ? ? }, 3000);
- ? ? },
- ? },
- };
- </script>
css代码 我这边用的是scss
- <style lang="scss" scoped>
- .box {
- ? text-align: center;
- ? height: 600px;
- ? width: 100vw;
- ? background-color: orange;
- ? position: absolute;
- ? left: 0;
- ? top: 0;
- }
- .car {
- ? text-align: center;
- ? margin: auto;
- ? width: 199px;
- ? height: 60px;
- ? line-height: 60px;
- ? background-position: 0 0;
- ? background-size: 100% auto;
- ? animation: animation_car 1.5s steps(1) infinite;
- }
- </style>
如果下拉刷新用动画就用这个css样式
图片的话我用的是28帧的 根据100除以28 也就是3.5 ,所以每3.5%换一个图,就能形成一个逐帧动画,每一个页面的宽高都不一样所以要计算 ,我的页面的大小是1080的这个也时我设置好的宽高。
这是代码
图片

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。