赞
踩
目录
4、animation-iteration-count:检索或设置对象动画的循环次数
5、animation-play-state:检索或设置对象动画的状态(running\paused)
-
- <template>
- <div class="test"></div>
- </template>
-
- <style lang="scss" scoped>
- .test {
- background-color: orange;
- width: 2rem;
- height: 2rem;
- border-radius: 50%;
-
- transition-duration: 1s;
-
- &:hover {
- width: 4rem;
- height: 4rem;
- }
- }
- </style>
-
- <template>
- <div class="test"></div>
- </template>
-
- <style lang="scss" scoped>
- .test {
- background-color: orange;
- width: 2rem;
- height: 2rem;
- border-radius: 50%;
-
- transition-duration: 1s;
- transition-property: height;
-
- &:hover {
- width: 4rem;
- height: 4rem;
- }
- }
- </style>
-
- <template>
- <div class="test"></div>
- </template>
-
- <style lang="scss" scoped>
- .test {
- background-color: orange;
- width: 2rem;
- height: 2rem;
- border-radius: 50%;
-
- transition-duration: 1s;
- transition-timing-function: ease-in-out;
-
- &:hover {
- width: 4rem;
- height: 4rem;
- }
- }
- </style>
-
- <template>
- <div class="test"></div>
- </template>
-
- <style lang="scss" scoped>
- .test {
- background-color: orange;
- width: 2rem;
- height: 2rem;
- border-radius: 50%;
-
- transition-delay: 1s;
-
- &:hover {
- width: 4rem;
- height: 4rem;
- }
- }
- </style>
几个属性的简写,如下:
-
- <template>
- <div class="test"></div>
- </template>
-
- <style lang="scss" scoped>
- .test {
- background-color: orange;
- width: 2rem;
- height: 2rem;
- border-radius: 50%;
-
- transition: all 1s ease-in-out 2s;//动画持续一秒,缓进缓出,并在两秒钟后开始执行
-
- &:hover {
- width: 4rem;
- height: 4rem;
- }
- }
- </style>
-
- <template>
- <div class="test"></div>
- </template>
-
- <style lang="scss" scoped>
- .test {
- background-color: orange;
- width: 2rem;
- height: 2rem;
- border-radius: 50%;
-
- &:hover {
- animation: mymove 2s;
- }
- }
- @keyframes mymove {
- 0% {
- width: 2rem;
- height: 2rem;
- }
- 50% {
- width: 4rem;
- height: 4rem;
- }
- 100% {
- width: 2rem;
- height: 2rem;
- margin-left: 5rem;
- }
- }
- </style>
其实上面的animation: mymove 2s;就是animation-name:mymove 和 animation-duration:2s; 的简写形式
-
- <template>
- <div class="test"></div>
- </template>
-
- <style lang="scss" scoped>
- .test {
- background-color: orange;
- width: 2rem;
- height: 2rem;
- border-radius: 50%;
-
- &:hover {
- animation: mymove 2s;
- animation-timing-function: ease-in-out;
- }
- }
- @keyframes mymove {
- 0% {
- width: 2rem;
- height: 2rem;
- }
- 50% {
- width: 4rem;
- height: 4rem;
- }
- 100% {
- width: 2rem;
- height: 2rem;
- margin-left: 5rem;
- }
- }
- </style>
-
- <template>
- <div class="test"></div>
- </template>
-
- <style lang="scss" scoped>
- .test {
- background-color: orange;
- width: 2rem;
- height: 2rem;
- border-radius: 50%;
-
- &:hover {
- animation: mymove 2s;
- animation-delay: 1s;
- }
- }
- @keyframes mymove {
- 0% {
- width: 2rem;
- height: 2rem;
- }
- 50% {
- width: 4rem;
- height: 4rem;
- }
- 100% {
- width: 2rem;
- height: 2rem;
- margin-left: 5rem;
- }
- }
- </style>
animation-iteration-count: infinite;表示无限循环
-
- <template>
- <div class="test"></div>
- </template>
-
- <style lang="scss" scoped>
- .test {
- background-color: orange;
- width: 2rem;
- height: 2rem;
- border-radius: 50%;
-
- animation: mymove 2s;
- animation-iteration-count: infinite;
- }
- @keyframes mymove {
- 0% {
- width: 2rem;
- height: 2rem;
- }
- 50% {
- width: 4rem;
- height: 4rem;
- }
- 100% {
- width: 2rem;
- height: 2rem;
- margin-left: 5rem;
- }
- }
- </style>
当然,还可以指定具体的循环次数,如下:
-
- <template>
- <div class="test"></div>
- </template>
-
- <style lang="scss" scoped>
- .test {
- background-color: orange;
- width: 2rem;
- height: 2rem;
- border-radius: 50%;
-
- animation: mymove 2s;
- animation-iteration-count: 3;//只循环三次
- }
- @keyframes mymove {
- 0% {
- width: 2rem;
- height: 2rem;
- }
- 50% {
- width: 4rem;
- height: 4rem;
- }
- 100% {
- width: 2rem;
- height: 2rem;
- margin-left: 5rem;
- }
- }
- </style>
-
- <template>
- <div class="test"></div>
- </template>
- <script>
- export default {
- name: "",
- components: {},
- data() {
- return {};
- },
- mounted() {
- setTimeout(() => {
- this.$refs.ref_test.style.animationPlayState = "paused";
- }, 3000);
- setTimeout(() => {
- this.$refs.ref_test.style.animationPlayState = "running";
- }, 5000);
- }
- };
- </script>
- <style lang="scss" scoped>
- .test {
- background-color: orange;
- width: 2rem;
- height: 2rem;
- border-radius: 50%;
-
- animation: mymove 2s;
- animation-iteration-count: 3;//只循环三次
- }
- @keyframes mymove {
- 0% {
- width: 2rem;
- height: 2rem;
- }
- 50% {
- width: 4rem;
- height: 4rem;
- }
- 100% {
- width: 2rem;
- height: 2rem;
- margin-left: 5rem;
- }
- }
- </style>
-
- <template>
- <div class="test"></div>
- </template>
-
- <style lang="scss" scoped>
- .test {
- background-color: orange;
- width: 2rem;
- height: 2rem;
- border-radius: 50%;
-
- animation: mymove 2s;
- animation-iteration-count: infinite;
- animation-direction: alternate;
-
- }
- @keyframes mymove {
- 0% {
- width: 2rem;
- height: 2rem;
- }
- 50% {
- width: 4rem;
- height: 4rem;
- }
- 100% {
- width: 2rem;
- height: 2rem;
- margin-left: 5rem;
- }
- }
- </style>
-
- <template>
- <img src="./二哈.jpg" />
- </template>
-
- <style lang="scss" scoped>
- img {
- width: 3rem;
- height: 4rem;
- border-radius: 50%;
- animation: myRotate 2s infinite linear;
- }
- @keyframes myRotate {
- 0% {
- transform: rotate(0);
- }
- 100% {
- transform: rotate(360deg);
- }
- }
- </style>
-
- <template>
- <img src="./二哈.jpg" />
- </template>
-
- <style lang="scss" scoped>
- img {
- width: 3rem;
- height: 4rem;
- border-radius: 50%;
- animation: myRotateX 2s infinite linear;
- }
- @keyframes myRotateX {
- 0% {
- transform: rotateX(0);
- }
- 100% {
- transform: rotateX(360deg);
- }
- }
- </style>
-
- <template>
- <img src="./二哈.jpg" />
- </template>
-
- <style lang="scss" scoped>
- img {
- width: 3rem;
- height: 4rem;
- border-radius: 50%;
- animation: myRotateY 2s infinite linear;
- }
- @keyframes myRotateY {
- 0% {
- transform: rotateY(0);
- }
- 100% {
- transform: rotateY(360deg);
- }
- }
- </style>
- <template>
- <div>
- <img src="./二哈.jpg" />
- </div>
- </template>
-
- <style lang="scss" scoped>
- img {
- width: 3rem;
- height: 4rem;
- border-radius: 50%;
-
- animation: myTranslate 2s infinite linear;
- }
- @keyframes myTranslate {
- 0% {
- transform: translate(0, 0);
- }
- 100% {
- transform: translate(8rem, 8rem);
- }
- }
- </style>
- <template>
- <div>
- <img src="./二哈.jpg" />
- </div>
- </template>
-
- <style lang="scss" scoped>
- img {
- width: 3rem;
- height: 4rem;
- border-radius: 50%;
-
- animation: myTranslateX 2s infinite linear;
- }
- @keyframes myTranslateX {
- 0% {
- transform: translateX(0);
- }
- 100% {
- transform: translateX(8rem);
- }
- }
- </style>
- <template>
- <div>
- <img src="./二哈.jpg" />
- </div>
- </template>
-
- <style lang="scss" scoped>
- img {
- width: 3rem;
- height: 4rem;
- border-radius: 50%;
-
- animation: myTranslateY 2s infinite linear;
- }
- @keyframes myTranslateY {
- 0% {
- transform: translateY(0);
- }
- 100% {
- transform: translateY(8rem);
- }
- }
- </style>
- <template>
- <div>
- <img src="./二哈.jpg" />
- </div>
- </template>
-
- <style lang="scss" scoped>
- img {
- width: 3rem;
- height: 4rem;
- border-radius: 50%;
-
- animation: myScale 2s infinite linear;
- }
- @keyframes myScale {
- 0% {
- transform: scale(0, 0);
- }
- 100% {
- transform: scale(1, 1);
- }
- }
- </style>
- <template>
- <div>
- <img src="./二哈.jpg" />
- </div>
- </template>
-
- <style lang="scss" scoped>
- img {
- width: 3rem;
- height: 4rem;
- border-radius: 50%;
-
- animation: myScaleX 2s infinite linear;
- }
- @keyframes myScaleX {
- 0% {
- transform: scaleX(0);
- }
- 100% {
- transform: scaleX(1);
- }
- }
- </style>
- <template>
- <div>
- <img src="./二哈.jpg" />
- </div>
- </template>
-
- <style lang="scss" scoped>
- img {
- width: 3rem;
- height: 4rem;
- border-radius: 50%;
-
- animation: myScaleY 2s infinite linear;
- }
- @keyframes myScaleY {
- 0% {
- transform: scaleY(0);
- }
- 100% {
- transform: scaleY(1);
- }
- }
- </style>
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。