这里是JS小提琴链接: http://jsfiddle.net/asif097/Vq8bp/
和CSS:
.hanging-div {
transition:all 1s;
-moz-transition:all 1s;
-webkit-transition:all 1s;
-o-transition:all 1s;
transform-origin:0% 0%;
-moz-transform-origin:0% 0%;
-webkit-transform-origin:0% 0%;
-ms-transform-origin:0% 0%;
-o-transform-origin:0% 0%;
}
.hanging-div:hover {
transform:rotate(30deg);
-ms-transform:rotate(30deg);
-moz-transform:rotate(30deg);
-webkit-transform:rotate(30deg);
-o-transform:rotate(30deg);
}
div在悬停时动画并悬停。我希望它能不断地保持动画(有点像钟摆)。我怎样才能做到这一点?
N.B。有没有办法用jquery实现相同的动画?
答案 0 :(得分:1)
为什么不简单地使用CSS @keyframes
创建一个无限animation-iteration-count
的动画:
@-moz-keyframes pendulum {
50% {
-moz-transform:rotate(30deg);
}
}
@-ms-keyframes pendulum {
50% {
-ms-transform:rotate(30deg);
}
}
@-o-keyframes pendulum {
50% {
-o-transform:rotate(30deg);
}
}
@-webkit-keyframes pendulum {
50% {
-webkit-transform:rotate(30deg);
}
}
@keyframes pendulum {
50% {
transform:rotate(30deg);
}
}
.hanging-div {
font-weight:600;
text-align:center;
color:#fff;
margin:0 auto;
display:block;
width:200px;
padding:50px 0;
background:#f00;
-moz-animation: pendulum;
-moz-animation-iteration-count: infinite;
-moz-animation-duration: 2s;
-moz-transform-origin: top left;
-ms-animation: pendulum;
-ms-animation-iteration-count: infinite;
-ms-animation-duration: 2s;
-ms-transform-origin: top left;
-o-animation: pendulum;
-o-animation-iteration-count: infinite;
-o-animation-duration: 2s;
-o-transform-origin: top left;
-webkit-animation: pendulum;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration: 2s;
-webkit-transform-origin: top left;
animation: pendulum;
animation-iteration-count: infinite;
animation-duration: 2s;
transform-origin: top left;
}