I need to get an image to rotate having its transform origin at 50% 50%. is the following correct? It does not seem to work for me.
function slideUp_Menu(){
$('.main_nav').slideUp('slow', function(){
$("#arrow_up").css({ "-webkit-transform": "rotate(180deg)" });
$("#arrow_up").css( "-webkit-transform-origin", "50% 50%");
});// $('.tab_wrapper').animate({ marginTop: '193px' }, 500, 'linear');
}
I would add the transitions to your class in css eg:
transition: transform 1s ease;
then create another class and in there set the transform eg:
transform: rotate(10deg);
Then I would use jquery to add/remove the class eg:
$(document).on('click', 'selector', function() {
$(this).addClass('class with transform');
});
Remember to include all the browser prefixes in your css selectors.
Js fiddle: http://jsfiddle.net/FhXj6/
no man its not correct and its for webkit supporting browsers!
function slideUp_Menu(){
$('.main_nav').slideUp('slow', function(){
$("#arrow_up").css({ "-moz-transform": "rotate(180deg)" });
$("#arrow_up").css( "-moz-transform-origin", "50% 50%");
$("#arrow_up").css({ "-webkit-transform": "rotate(180deg)" });
$("#arrow_up").css( "-webkit-transform-origin", "50% 50%");
$("#arrow_up").css({ "transform": "rotate(180deg)" });
$("#arrow_up").css( "transform-origin", "50% 50%");
});// $('.tab_wrapper').animate({ marginTop: '193px' }, 500, 'linear');
}
You could probably do it with jQuery but I'd recommend using Greensock for animations:
https://www.greensock.com/gsap-js/
the performance is far better and stuff like rotating is a breeze. Use .get(0) at the end of your selector and jQuery is a fine partner :)
TweenMax.to($("#arrow_up").get(0), {css:{rotation:180}});
If you want transform origin look here:
https://www.greensock.com/get-started-js/
"transformOrigin – Sets the origin around which all transforms occur. By default, it is in the center of the element ("50% 50%")."
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.