javascript - jQuery Rotate Image Not On Center - Stack Overflow

I'm having a bit of an issue trying to rotate an image on a particular point.I've been using

I'm having a bit of an issue trying to rotate an image on a particular point.

I've been using / as an example; which works perfectly when wanting to rotate an image from its center point.

However, using the example above, i wanted to rotate the image around the letter G, how could this be achieved?

Current code:

function rotateGearStick()
{
var rotation = function (){
       $("#gear-stick").rotate({
          angle:0, 
          animateTo:110, 
       });
    }
    rotation();
}

Where gear-stick is the ID of my image.

I'm attempting to create an rev counter dial.

I'm having a bit of an issue trying to rotate an image on a particular point.

I've been using http://jsfiddle/YKj5D/ as an example; which works perfectly when wanting to rotate an image from its center point.

However, using the example above, i wanted to rotate the image around the letter G, how could this be achieved?

Current code:

function rotateGearStick()
{
var rotation = function (){
       $("#gear-stick").rotate({
          angle:0, 
          animateTo:110, 
       });
    }
    rotation();
}

Where gear-stick is the ID of my image.

I'm attempting to create an rev counter dial.

Share Improve this question edited May 3, 2013 at 7:53 Anujith 9,3706 gold badges35 silver badges48 bronze badges asked May 3, 2013 at 7:53 Oam PsyOam Psy 8,66335 gold badges97 silver badges167 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 2

http://jsfiddle/YKj5D/1988/

#image{
    margin:100px;
    padding-left:170px; /* <----- */
}

I find this a lot more cleaner fix.

#image{
    -webkit-transform-origin:0px 0px;
    -moz-transform-origin:0px 0px;
    -ms-transform-origin:0px 0px;
    transform-origin:0px 0px; //px or percent whichever you prefer
}

Just change the origin values to whatever suits your needs and it will rotate about that origin.

Recent version of jQueryRotate handles changing center of rotation cross-browse. Using padding-only solution will not work for a fallbacks to CANVAS/VML. Please check http://jqueryrotate.googlecode.

The http://jqueryrotate.googlecode. (suggested by Wilq32 in above post) documentation says adding the "center" attribute as shown below. It takes a array of length 2 of absolute pixel position or percentage. I.e. center: ["150px", "100px"] OR center: ["60%", "50%"]

var rotation = function (){
  $("#image").rotate({
      angle:0, 
      animateTo:360, 
      center: ["150px", "100px"], 
      callback: rotation
  });
}

rotation();

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

相关推荐

  • javascript - jQuery Rotate Image Not On Center - Stack Overflow

    I'm having a bit of an issue trying to rotate an image on a particular point.I've been using

    9小时前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信