Trying to rotate a div element...This might be DOM blasphemy, could it work possibly with a canvas element? I'm not sure - if anybody has any ideas of how this could work or why it doesn't, I'd love to know. Thanks.
<? php echo "<img src='down_arrow. png' onclick='$(this). animate({rotate: \"+=90deg\"});' />"; ?>
The CSS rotate() function lets you rotate an element on a 2D axis. The rotate() function accepts one argument: the angle at which you want to rotate your web element. You can rotate an element clockwise or counter-clockwise.
To rotate a DIV Make use of WebkitTransform / -moz-transform: rotate(Xdeg)
.
This will not work in IE. The Raphael library does work with IE and it does rotation. I believe it uses canvas
es
If you want to animate the rotation, you can use a recursive setTimeout()
You could probably even do part of a spin with jQuery's .animate()
Make sure that you consider the width of your element. If rotate an that has a larger width than its visible content, you'll get funny results. However you can narrow the widths of elements, and then rotate them.
Here is a simply jQuery snippet that rotates the elements in a jQuery object. Rotatation can be started and stopped:
$(function() { var $elie = $(selectorForElementsToRotate); rotate(0); function rotate(degree) { // For webkit browsers: e.g. Chrome $elie.css({ WebkitTransform: 'rotate(' + degree + 'deg)'}); // For Mozilla browser: e.g. Firefox $elie.css({ '-moz-transform': 'rotate(' + degree + 'deg)'}); // Animate rotation with a recursive call setTimeout(function() { rotate(++degree); },5); } });
Note:
Taking the degree and increasing it, will rotate the image clockwise. Decreasing the degree of rotation will rotate the image counter clockwise.
yeah you're not going to have much luck i think. Typically across the 3 drawing methods the major browsers use (Canvas, SVG, VML), text support is poor, I believe. If you want to rotate an image, then it's all good, but if you've got mixed content with formatting and styles, probably not.
Check out RaphaelJS for a cross-browser drawing API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With