Reputation: 164
I need logo to rotate in 400degree and then rotate back on 360 degree on mouseOver, then on mouseOut it should roate -400 and then back for 40 degree. Here is what i accomplished.
$("#logo").rotate({
bind:
{
mouseover : function() {
$(this).rotate({animateTo:400})
},
mouseout : function() {
$(this).rotate({animateTo:-40})
}
}
});
Upvotes: 2
Views: 150
Reputation: 7473
you need to add 2 extra arguments for the rotate function:
your code would look like that:
$("#logo").rotate({
bind: {
mouseover: function () {
$(this).rotate({
animateTo: 400,
callback: function () {
$(this).rotate({
animateTo: 360
});
},
duration: 400
});
},
mouseout: function () {
$(this).rotate({
animateTo: -40,
callback: function () {
$(this).rotate({
animateTo: 0
});
},
duration: 400
});
}
}
});
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="http://jqueryrotate.googlecode.com/svn/trunk/jQueryRotate.js"></script>
<img id="logo" src="http://www.keecker.com/img/logo_circle.png">
UPDATE:
for future reference, people who prefer to achieve the same with pure css, here is a possible solution:
#logo {
-webkit-animation: rotate_backwards 1s forwards;
animation: rotate_backwards 1s;
}
#logo:hover {
-webkit-animation: rotate_forward 1s forwards;
animation: rotate_forward 1s;
}
@-webkit-keyframes rotate_forward {
60% {
-webkit-transform:rotate(400deg);
}
100%{
-webkit-transform:rotate(360deg);
}
}
@-webkit-keyframes rotate_backwards {
60% {
-webkit-transform:rotate(-400deg);
}
100%{
-webkit-transform:rotate(-360deg);
}
}
@keyframes rotate_forward {
60% {
transform:rotate(400deg);
}
100%{
transform:rotate(360deg);
}
}
@keyframes rotate_backwards {
60% {
transform:rotate(-400deg);
}
100%{
transform:rotate(-360deg);
}
}
<img id="logo" src="http://www.keecker.com/img/logo_circle.png">
Upvotes: 1
Reputation: 24001
If you need action only on hover ..simple to use css :hover instead of javascript
#logo{
-ms-transform: rotate(0deg); /* IE 9 */
-webkit-transform: rotate(0deg); /* Chrome, Safari, Opera */
transform: rotate(0deg);
transition-duration: 0.5s;
}
#logo:hover {
-ms-transform: rotate(360deg); /* IE 9 */
-webkit-transform: rotate(360deg); /* Chrome, Safari, Opera */
transform: rotate(360deg);
transition-duration: 0.5s;
}
Upvotes: 1
Reputation: 206467
#logo {margin:30px; transition:1s;}
#logo:hover{transform:rotate(-400deg);}
<img id="logo" src="//placehold.it/100x100/f0f&text=LOGO">
Upvotes: 2