vue+animation实现翻页动画


Posted in Javascript onJune 29, 2020

本文实例为大家分享了vue+animation实现翻页动画展示的具体代码,供大家参考,具体内容如下

前端在做数据展示的时候,可能提留页面时间较长,导致数据不能及时更新,你可以定时更新,也可以做一个假数据 给用户视觉上的体验,接下来就是第二种,假数据,它用了C3 animation 实现了一个翻页动画。

vue+animation实现翻页动画

第一种是单独运动

<template>
 <div>
 <div>
  <ul>
  <li v-for="(item,i) in NumberList" :key="i" ><a :class="[item.isMove ? 'move-an' : '']">{{item.num}}</a></li>
  </ul>
 </div>
 </div>
</template>
<script>
export default {
 data(){
 return {
  NumberList:'',
  Number:108847,
 }
 },
 mounted(){
 let arr = String(this.Number).split('')
 this.NumberList=[]
 arr.forEach(item => {
  const model = {};
  model.isMove = false;
  model.num = item;
  this.NumberList.push(model);
 });
 setInterval(() =>{
  this.Number=this.Number+1;
  let data = String(this.Number);
  let arr = data.split("");
  arr.forEach((item, index) => {
  if (item !== this.NumberList[index].num) {
   this.NumberList[index].isMove = true
  }
  });
 }, 10000)
 },
 watch: {
 Number() {
  setTimeout(() =>{
  let data = String(this.Number);
  let arr = data.split("");
  this.NumberList.forEach((item, index) => {
  this.NumberList[index].num = arr[index];
  });
  }, 500);
  setTimeout(() =>{
  this.NumberList.forEach((item, index) => {
  this.NumberList[index].isMove = false
  });
  }, 1000);
 }
 },
 methods:{
 }
}
</script>
<style lang="" scoped>
 h1{
 text-align:center;
 }
 ul{
 display: flex;
 
 }
 li{
 list-style: none;
 width:50px;height:80px;
 background: red;
 margin-right: 10px;
 text-align: center;
 line-height: 80px;
 font-size:20px;
 color:#ffffff;
 position: relative;
 }
 a {
 position: absolute;
 top: 3px;
 color: #ffffff;
 }
 .move-an {
 animation:mymove 1s infinite linear;
 -webkit-animation:mymove 1s infinite linear;
 }
 @keyframes mymove {
 0% {top: 3px;}
 25% {top: -40px;}
 48% {top: -80px;}
 49% {top: -80px; opacity: 0}
 50% {top: 80px;}
 51% {top: 80px;opacity: 1; }
 100% {top: 3px;}
 }
</style>

第二种是整体运动 0-9循环一边

<template>
 <div class="main">
 <div v-for="(item,i) in NumberList" class="move-num" :key="i">
  <div>
  <div style="visibility:hidden;position: static">
   <span v-for="(list, i) in item.num" :key="i" class="num-move">{{list}}</span>
  </div>
  <a :class="[isMove === true ? 'move-an' : '']">
   <span v-for="(list, i) in item.num" :key="i" class="num-move">{{list}}</span>
  </a>
  </div>
 </div>
 </div>
</template>
<script>
export default {
 data(){
 return {
  isMove:false,
  NumberList:[],
  Number:108847,
  numModels: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
 }
 },
 mounted(){
 this.handdleDate()
 setInterval(() => {
  this.handdleDate()
 }, 10000)
 },
 methods:{
 handdleDate(){
  let arr = String(this.Number).split('')
  this.NumberList=[]
  arr.forEach(item => {
  
  const model = {}
  const baseArr = JSON.parse(JSON.stringify(this.numModels))
  model.isMove = false;
  for (let i = 0; i < parseInt(item) + 1; i++) {
   baseArr.push(i)
  }
  model.num = baseArr;
  this.NumberList.push(model);
  this.isMove = true;
   setTimeout(() => {
   this.isMove = false
  }, 3000)
  });
 }
 }
}
</script>
<style lang="" scoped>
.main{
 display: flex;
}
.move-num{
 width:30px;height:40px;
 background:red;
 overflow: hidden;
 margin-right:10px;
 line-height: 40px;
 color:#fff;
 position: relative;
 overflow: hidden;
}
.move-num div {
 position: absolute;
 width: 100%;
 height: auto;
 
 }
.move-num div a {
 color: #ffffff;
 display: block;
 position: absolute;
 left: 10px;
 bottom: calc(100% - 45px);
}
.num-move {
 width: 100%;
 display: block;
 margin: 3px 0;
}
.move-an {
 animation:mymove 3s infinite linear forwards;
 -webkit-animation:mymove 3s infinite linear forwards;
}
.num-move {
 width: 100%;
 display: block;
 margin: 3px 0;
}
@keyframes mymove {
 0% {bottom: 3px;}
 100% {bottom: calc(100% - 40px)}
}
</style>

关于vue.js组件的教程,请大家点击专题vue.js组件学习教程进行学习。

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

Javascript 相关文章推荐
LBS blog sql注射漏洞[All version]-官方已有补丁
Aug 26 Javascript
js 中{},[]中括号,大括号使用详解
May 12 Javascript
关于Jquery操作Cookie取值错误的解决方法
Aug 26 Javascript
倒记时60刷新网页的js代码
Feb 18 Javascript
js 动态修改css文件用到了cssRule
Aug 20 Javascript
两种方法基于jQuery实现IE浏览器兼容placeholder效果
Oct 14 Javascript
JS集成fckeditor及判断内容是否为空的方法
May 27 Javascript
jQuery得到多个值只能用取Class ,不能用取ID的方法
Dec 04 Javascript
EditPlus中的正则表达式 实战(2)
Dec 15 Javascript
Vue组件之Tooltip的示例代码
Oct 18 Javascript
轻量级JS Cookie插件js-cookie的使用方法
Mar 22 Javascript
微信小程序手动添加收货地址省市区联动
May 18 Javascript
vue+element实现图片上传及裁剪功能
Jun 29 #Javascript
vue实现匀速轮播效果
Jun 29 #Javascript
vant实现购物车功能
Jun 29 #Javascript
js实现随机点名器精简版
Jun 29 #Javascript
Node.js中出现未捕获异常的处理方法
Jun 29 #Javascript
在Vue中使用antv的示例代码
Jun 29 #Javascript
vue实现一个6个输入框的验证码输入组件功能的实例代码
Jun 29 #Javascript
You might like
phpStudy访问速度慢和启动失败的解决办法
2015/11/19 PHP
window.addeventjs事件驱动函数集合addEvent等
2008/02/19 Javascript
JQuery困惑—包装集 DOM节点
2009/10/16 Javascript
jquery ui对话框实例代码
2013/05/10 Javascript
jquery将一个表单序列化为一个对象的方法
2014/01/03 Javascript
window.open()实现post传递参数
2015/03/12 Javascript
jQuery下拉友情链接美化效果代码分享
2015/08/26 Javascript
简单理解Vue中的nextTick方法
2018/01/30 Javascript
Vue 源码分析之 Observer实现过程
2018/03/29 Javascript
vue中的自定义分页插件组件的示例
2018/08/18 Javascript
NodeJs 文件系统操作模块fs使用方法详解
2018/11/26 NodeJs
javascript 关于赋值、浅拷贝、深拷贝的个人理解
2019/11/01 Javascript
node.js使用zlib模块进行数据压缩和解压操作示例
2020/02/12 Javascript
用Angular实现一个扫雷的游戏示例
2020/05/15 Javascript
[01:15:36]加油刀塔第二期网络版
2014/08/09 DOTA
python client使用http post 到server端的代码
2013/02/10 Python
Python闭包之返回函数的函数用法示例
2018/01/27 Python
python 模拟贷款卡号生成规则过程解析
2019/08/30 Python
将数据集制作成VOC数据集格式的实例
2020/02/17 Python
css3 border旋转时的动画应用
2016/01/22 HTML / CSS
办公室助理岗位职责
2013/12/25 职场文书
买房子个人收入证明
2014/01/16 职场文书
个人能力自我鉴赏
2014/01/25 职场文书
物业管理专业求职信
2014/06/11 职场文书
三好生演讲稿
2014/09/12 职场文书
2014年预备党员群众路线教育实践活动对照检查材料思想汇报
2014/10/02 职场文书
习总书记三严三实学习心得体会
2014/10/13 职场文书
小学六年级班主任工作经验交流材料
2015/11/02 职场文书
创业计划书之废品回收
2019/09/26 职场文书
Python 制作自动化翻译工具
2021/04/25 Python
Golang 实现超大文件读取的两种方法
2021/04/27 Golang
Golang 使用Map实现去重与set的功能操作
2021/04/29 Golang
解决Navicat for MySQL 连接 MySQL 报2005错误的问题
2021/05/29 MySQL
MySQL 聚合函数排序
2021/07/16 MySQL
OpenCV 图像梯度的实现方法
2021/07/25 Python
MySQL示例讲解数据库约束以及表的设计
2022/06/16 MySQL