最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Css animation when go back to initial style - Stack Overflow

programmeradmin1浏览0评论

I have scale animation on image, but when the animation finish and go back to the initial size there is no animation, how can i force animation when go back to the initial value?

,css,output

@keyframes scaleImg {
    from {
        transform: scale(0.8);
    }
    to {
        transform: scale(1);
    }
}

img { 
   transform: scale(0.8);
   animation: scaleImg 1.5s;
   animation-direction: alternate;
}



<img src="/" alt="">

I have scale animation on image, but when the animation finish and go back to the initial size there is no animation, how can i force animation when go back to the initial value?

http://jsbin./tijapahuwi/edit?html,css,output

@keyframes scaleImg {
    from {
        transform: scale(0.8);
    }
    to {
        transform: scale(1);
    }
}

img { 
   transform: scale(0.8);
   animation: scaleImg 1.5s;
   animation-direction: alternate;
}



<img src="http://lorempixel./400/200/sports/" alt="">
Share Improve this question asked Nov 26, 2015 at 8:13 user233232user233232 6,2179 gold badges30 silver badges37 bronze badges 1
  • 1 animation-iteration-count: 2; – Jaromanda X Commented Nov 26, 2015 at 8:20
Add a ment  | 

3 Answers 3

Reset to default 6

animation-direction: alternate; is a good start

each iteration runs in alternate direction

so, 2 iterations to get back where you started - i.e.

animation-iteration-count: 2;

Of course, if you want the total time to be 1.5s, you'll want to change the 1.5s to 750ms as well

How is it with?:

@keyframes scaleImg {
    0% {
        transform: scale(0.8);
    }
    50% {
        transform: scale(1);
    }
    100% {
        transform: scale(0.8);
    }
}

img { 
   transform: scale(0.8);
   animation: scaleImg 1.5s;
   animation-timing-function: linear;
}

try this solution

@keyframes scaleImg {
    0% {
    transform: scale(0.8);
}
50% {
    transform: scale(1);
}
100% {
    transform: scale(0.8);
}

img { 
   transform: scale(0.8);
   animation: scaleImg 1.5s;
   animation-direction: alternate;
}

Hope this help you.

发布评论

评论列表(0)

  1. 暂无评论