javascript - On hover image rotate 45 degrees - Stack Overflow

I'm trying to rotate an image 45 degree (well actually I really want to make it wiggle back and fo

I'm trying to rotate an image 45 degree (well actually I really want to make it wiggle back and forth) when I hover over. I tried using CSS with the transform rotate with no luck. Does anyone have any ideas (jQuery, javascript maybe)?

  a:hover{
            behavior:url(-ms-transform.htc);
            /* Firefox */
            -moz-transform:rotate(45deg);
            /* Safari and Chrome */
            -webkit-transform:rotate(45deg);
            /* Opera */
            -o-transform:rotate(45deg);
            /* IE9 */
            -ms-transform:rotate(45deg);
            /* IE6,IE7 */}

 <div id="main">
    <span class="box"><a href=""><img src="blog-icon.png"></img></a></span>
 </div>

I'm trying to rotate an image 45 degree (well actually I really want to make it wiggle back and forth) when I hover over. I tried using CSS with the transform rotate with no luck. Does anyone have any ideas (jQuery, javascript maybe)?

  a:hover{
            behavior:url(-ms-transform.htc);
            /* Firefox */
            -moz-transform:rotate(45deg);
            /* Safari and Chrome */
            -webkit-transform:rotate(45deg);
            /* Opera */
            -o-transform:rotate(45deg);
            /* IE9 */
            -ms-transform:rotate(45deg);
            /* IE6,IE7 */}

 <div id="main">
    <span class="box"><a href=""><img src="blog-icon.png"></img></a></span>
 </div>
Share Improve this question asked Nov 15, 2012 at 7:16 John VerberJohn Verber 7552 gold badges16 silver badges32 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

You seem to be setting the hover to the anchor instead of image..

Instead of

a:hover{

should be

img:hover{

Check Fiddle

In webkit browsers,transform is ignored on inline elements.

To make this work you would need to add a { display:block; } to your css. (Inline-block will also work)

Demo: http://jsfiddle/6Df6W/

Try This:

$("a img").rotate({ 
   bind: 
     { 
        mouseover : function() { 
            $(this).rotate({animateTo:45})
        },
        mouseout : function() { 
            $(this).rotate({animateTo:0})
        }
     } 

});​

I've used this several times and it works well:

http://code.google./p/jqueryrotate/

$(".box a img").rotate(45);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744769523a4592672.html

相关推荐

  • javascript - On hover image rotate 45 degrees - Stack Overflow

    I'm trying to rotate an image 45 degree (well actually I really want to make it wiggle back and fo

    15小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信