Hello I have a div I want to center controlled by jQuery. I would like to move the div to the center of the page on click. To do this I set up a jQuery function to affect the positioning through css. It works, but its not transitioning smoothly, it happens instantly even if I add the css transitions. Below is my code I have so far
Here is the css:
.footer-active-line {
height: 10px;
width: 33.3333333333%;
-webkit-transition: all .25s ease-in-out;
-moz-transition: all .25s ease-in-out;
-ms-transition: all .25s ease-in-out;
-o-transition: all .25s ease-in-out;
transition: all .25s ease-in-out;
}
Here is the jQuery:
jQuery(".footer-locations-box2").click(function(){
jQuery(".footer-active-line").css({ 'right': '0px', 'left': '0', 'margin': '0 auto' })
});
This code works, the div gets centered but the transition isnt kicking in. Does anyone know a way to make the transition smooth?
Thanks!
marginproperty from0toauto(that's what makes it centered), but CSS transitions are limited and can't transition to or fromauto. What you are trying to do is not possible with the current state of CSS. You could try transitiontransform:translateX()instead, but it would take some calculating of the percentages.jQuery(".footer-active-line").css({ margin: '0 33.33333%' });would work too. You're width is 33%,margin: 0 autowill result in about33%on either side.