0

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');
        }

3 Answers 3

2

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/

Sign up to request clarification or add additional context in comments.

Comments

0

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');
    }

Comments

0

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%")."

1 Comment

You don't even need to .get(0), TweenMax accepts jQuery wrapped objects / selections.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.