0

here is JS fiddle link: http://jsfiddle.net/asif097/Vq8bp/

and 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);
}

The div animates while hover and hover out. I want it to keep it animated continuously (a little bit similar to pendulum). How can I achieve that?

N.B. Is there a way to achieve the same animation with jquery?

4

1 回答 1

1

Why not simply use the CSS @keyframes to create an animation with an infinite 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;
}

JS Fiddle demo.

于 2013-03-30T20:26:09.423 回答