您的位置:首页 > 娱乐 > 八卦 > Vue 旋转动画效果

Vue 旋转动画效果

2024/10/7 6:38:35 来源:https://blog.csdn.net/qq_54855933/article/details/141360860  浏览:    关键词:Vue 旋转动画效果

目录

    • 前言
    • 效果演示
    • 具体代码实现

前言

    这里记录一个旋转动画,在鼠标经过的时候停止,鼠标离开继续旋转。

    实现思路: 利用@keyframes关键字定义一个旋转动画

效果演示

在这里插入图片描述

具体代码实现

<template><div class="container"><div class="box"  @mouseenter=" stopRotate = true " @mouseleave=" stopRotate = false " ><!-- 旋转图片--><img alt="Vue logo" class="rotate-icon"  :class="{'paused': stopRotate === true}" src="./assets/logo.svg" /></div></div>
</template><script>
export default {name: 'App',data(){return{stopRotate:false //控制是否旋转}}
}
</script><style lang="scss" scoped>
.container{width:100vw;height:100vh;position:relative;background-color:#000000;.box{width: 48px;height: 48px;background: #ffffff;border-radius: 50%;position:absolute;left:50%;top:30%;transform:translateX(-50%);display: flex;justify-content:center;align-items: center;&:hover{cursor: pointer;}.rotate-icon{width: 24px;height: 24px;//旋转动画animation: rotate 3s linear infinite;}@keyframes rotate {  from {  transform: rotate(0deg);  }  to {  transform: rotate(360deg);  }  }// 控制动画暂停.paused {  animation-play-state: paused;  } }
}
</style>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com