vue ajax加载动画,vue页面加载动画效果的实现

本文主要和大家详细介绍了vue实现页面加载动画效果,vue页面出现正在加载的初始页面与实现动画效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能帮助到大家。

:style="{background: option.background,color: option.color||'#fff'}"

:class="{'page-before': option.index < currentPage,

'page-after': option.index > currentPage,

'page-current': option.index === currentPage}">

页面正在渲染中。。。

有木有感觉很简单

下面上点干货,实现页面的动画效果

export default {

name: 'page-controller',

props: {

pageNum: Number,

currentPage: Number,

option: {

type: Object,

default: {

arrowsType: 'animate',

navbar: true,

highlight: true,

loop: true //是否开启滚动循环

}

}

},

methods: {

changePage (index) {

this.$emit('changePage', index);

}

},

computed: {

nextIndex () {

if (this.currentPage === this.pageNum) {

if(this.option.loop){

return 1

}else{

return this.pageNum

}

} else {

return this.currentPage + 1;

}

},

prevIndex () {

if (this.currentPage === 1) {

if(this.option.loop){

return this.pageNum

}else{

return 1

}

} else {

return this.currentPage - 1;

}

}

},

created () {

if (this.option.navbar === undefined) {

this.option.navbar = true;

}

},

mounted () {

let _this = this;

let timer = null;

let start = 0;

// 滚轮处理

function scrollHandler (direction) {

// 防止重复触发滚动事件

if (timer != null) {

return;

}

if (direction === 'down') {

_this.changePage(_this.nextIndex);

} else {

_this.changePage(_this.prevIndex);

}

timer = setTimeout(function() {

clearTimeout(timer);

timer = null;

}, 300);

}

// if (Object.hasOwnProperty.call(window,'onmousewheel')) {

if (Object.hasOwnProperty.call(window,'onmousewheel')) {

// 监听滚轮事件

window.addEventListener('mousewheel',function (event) { // IE/Opera/Chrome

let direction = event.wheelDelta > 0 ? 'up':'down';

scrollHandler(direction);

},false);

} else {

window.addEventListener('DOMMouseScroll',function (event) { // Firefox

let direction = event.detail > 0 ? 'up':'down';

scrollHandler(direction);

},false);

}

// 移动端触摸事件处理

window.addEventListener('touchstart', function (event) {

start = event.touches[0].clientY;

})

window.addEventListener('touchmove', function (event) {

event.preventDefault();

})

window.addEventListener('touchend', function (event) {

let spacing = event.changedTouches[0].clientY - start;

let direction;

if (spacing > 50) {

direction = 'up';

scrollHandler(direction);

} else if (spacing < -50) {

direction = 'down';

scrollHandler(direction);

}

})

}

}

.controller {

position: fixed;

right: 20px;

top: 50%;

z-index: 99;

}

.controller ul {

transform: translate3d(0,-50%,0);

list-style: none;

margin: 0;

padding: 0;

}

.controller-item {

cursor: pointer;

width: 20px;

height: 20px;

border-radius: 50%;

margin-top: 10px;

background-color: rgba(255, 255, 255, 0.3);

transition: background-color 0.3s ease 0s;

}

.controller-item:hover {

background-color: rgba(255, 255, 255, 0.7);

}

.controller-item.current {

background-color: rgba(255, 255, 255, 1);

}

.prev-btn,.next-btn {

cursor: pointer;

display: block;

text-align: center;

width: 20px;

height: 20px;

position: fixed;

left: 50%;

margin-left: -10px;

border: 4px solid #fff;

background-color: transparent;

outline: none;

}

.prev-btn {

top: 80px;

transform: rotate(-45deg);

border-bottom-color: transparent;

border-left-color: transparent;

}

.next-btn {

bottom: 80px;

transform: rotate(45deg);

border-top-color: transparent;

border-left-color: transparent;

}

.prev-btn.moving {

animation: prev-up-down 0.7s linear 0s infinite;

}

.next-btn.moving {

animation: next-up-down 0.7s linear 0s infinite;

}

@keyframes next-up-down {

0% {

transform: translate3d(0,0,0) rotate(45deg);

}

25% {

transform: translate3d(0,6px,0) rotate(45deg);

}

50% {

transform: translate3d(0,0,0) rotate(45deg);

}

75% {

transform: translate3d(0,-6px,0) rotate(45deg);

}

100% {

transform: translate3d(0,0,0) rotate(45deg);

}

}

@keyframes prev-up-down {

0% {

transform: translate3d(0,0,0) rotate(-45deg);

}

25% {

transform: translate3d(0,-6px,0) rotate(-45deg);

}

50% {

transform: translate3d(0,0,0) rotate(-45deg);

}

75% {

transform: translate3d(0,6px,0) rotate(-45deg);

}

100% {

transform: translate3d(0,0,0) rotate(-45deg);

}

}

本文已被整理到了《Vue.js前端组件学习教程》,欢迎大家学习阅读。

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

相关推荐:

Java在窗口上加载显示GIF动画图像,将多个独立的GIF图像串联在一起显示,形成GIF特有的动画形式。主要代码如下:   ImageIcon[] images; //用于动画的图标数组   Timer animationTimer;   int currentImage = 0; //当前图像编号   int delay = 500; //图像切换延迟   int width; //图像宽度   int height; //图像高度   public AnimatorIcon() //构造函数   {    setBackground(Color.white);    images = new ImageIcon[2]; //初始化数组    for (int i=0;i   images[i]=new ImageIcon(getClass().getResource("image" i ".gif")); //实例化图标    width = images[0].getIconWidth(); //初始化宽度值    height = images[0].getIconHeight(); //初始化高度值   }   public void paintComponent(Graphics g) { //重载组件绘制方法    super.paintComponent(g); //调用父类函数    images[currentImage].paintIcon(this,g,70,0); //绘制图标    currentImage=(currentImage 1)%2; //更改当前图像编号   }   public void actionPerformed(ActionEvent actionEvent) {    repaint();   }   public void startAnimation() { //开始动画    if (animationTimer==null) {    currentImage=0;    animationTimer=new Timer(delay, this); //实例化Timer对象    animationTimer.start(); //开始运行    } else if (!animationTimer.isRunning()) //如果没有运行    animationTimer.restart(); //重新运行   }   public void stopAnimation() {    animationTimer.stop(); //停止动画   }   public static void main(String args[]) {    AnimatorIcon animation = new AnimatorIcon(); //实例化动画图标    JFrame frame = new JFrame("动画图标"); //实例化窗口对象    frame.getContentPane().add(animation); //增加组件到窗口上    frame.setSize(200, 100); //设置窗口尺寸    frame.setVisible(true); //设置窗口可视    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //关闭窗口时退出程序    animation.startAnimation(); //开始动画
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值