CSS实现鼠标经过图片抖动效果

CSS实现鼠标经过图片抖动效果

把如下代码添加到style.css(模板的主css里面)

/**图片抖动**/

img:hover{-webkit-animation: tada 1s .2s ease both;-moz-animation: tada 1s .2s ease both;}

@-webkit-keyframes tada{0%{-webkit-transform:scale(1);}

10%, 20%{-webkit-transform:scale(0.9) rotate(-3deg);}

30%, 50%, 70%, 90%{-webkit-transform:scale(1.1) rotate(3deg);}

40%, 60%, 80%{-webkit-transform:scale(1.1) rotate(-3deg);}

100%{-webkit-transform:scale(1) rotate(0);}}

@-moz-keyframes tada{0%{-moz-transform:scale(1);}

10%, 20%{-moz-transform:scale(0.9) rotate(-3deg);}

30%, 50%, 70%, 90%{-moz-transform:scale(1.1) rotate(3deg);}

40%, 60%, 80%{-moz-transform:scale(1.1) rotate(-3deg);}

100%{-moz-transform:scale(1) rotate(0);}}

@-webkit-keyframes flipInY{0%{-webkit-transform:perspective(400px) rotateY(90deg);

opacity:0;}

40%{-webkit-transform:perspective(400px) rotateY(-10deg);}

70%{-webkit-transform:perspective(400px) rotateY(10deg);}

100%{-webkit-transform:perspective(400px) rotateY(0deg);

opacity:1;}}

@-moz-keyframes flipInY{0%{-moz-transform:perspective(400px) rotateY(90deg);

opacity:0;}

40%{-moz-transform:perspective(400px) rotateY(-10deg);}

70%{-moz-transform:perspective(400px) rotateY(10deg);}

100%{-moz-transform:perspective(400px) rotateY(0deg);

opacity:1;}}

如果想要实现部分图片抖动,只需在需要抖动的img前面div添加class属性=dimg,css代码如下:

/**图片抖动**/

.dimg img:hover{-webkit-animation: tada 1s .2s ease both;-moz-animation: tada 1s .2s ease both;}

@-webkit-keyframes tada{0%{-webkit-transform:scale(1);}

10%, 20%{-webkit-transform:scale(0.9) rotate(-3deg);}

30%, 50%, 70%, 90%{-webkit-transform:scale(1.1) rotate(3deg);}

40%, 60%, 80%{-webkit-transform:scale(1.1) rotate(-3deg);}

100%{-webkit-transform:scale(1) rotate(0);}}

@-moz-keyframes tada{0%{-moz-transform:scale(1);}

10%, 20%{-moz-transform:scale(0.9) rotate(-3deg);}

30%, 50%, 70%, 90%{-moz-transform:scale(1.1) rotate(3deg);}

40%, 60%, 80%{-moz-transform:scale(1.1) rotate(-3deg);}

100%{-moz-transform:scale(1) rotate(0);}}

@-webkit-keyframes flipInY{0%{-webkit-transform:perspective(400px) rotateY(90deg);

opacity:0;}

40%{-webkit-transform:perspective(400px) rotateY(-10deg);}

70%{-webkit-transform:perspective(400px) rotateY(10deg);}

100%{-webkit-transform:perspective(400px) rotateY(0deg);

opacity:1;}}

@-moz-keyframes flipInY{0%{-moz-transform:perspective(400px) rotateY(90deg);

opacity:0;}

40%{-moz-transform:perspective(400px) rotateY(-10deg);}

70%{-moz-transform:perspective(400px) rotateY(10deg);}

100%{-moz-transform:perspective(400px) rotateY(0deg);

opacity:1;}}
© 版权声明
THE END
喜欢就支持一下吧
点赞26赞赏
分享
评论 抢沙发

请登录后发表评论