Looking for some ideas of what is possible for my project.
I have a container div into which I load content dynamically. If I want the content centered, I have classes that I put on the container div (.center-content) and on the contained divs (#container .center-content). If I don't want them centered I remove the classes with removeClass(). No problem there.
Here's what I need help with: When, say, I remove the .centered classes, the divs will of course move rather abruptly to their new position. I want them to more saunter over all sexy-like.
Is there a css transition strategy I can apply whereby if a class being added or removed causes the div to relocate I can animate it's movement (i.e. slow or fast)?
I've used explicit css animations before as effects, but this seems a little different annnd I don't know what's possible and what's not possible.
Thanks,
Joel
Here's a jsfiddle as an example. http://jsfiddle.net/zdbbf/1/
What I would like is for the transition to be smoother when the centering is removed.
HTML:
<div id="mycontainer" class='centered'>
<div id="mycontent" class='centered'>
<span>I'm a centered div</span>
</div>
<button id="mybutton">click to remove centering</button>
</div>
CSS:
#mycontainer {
height: 400px;
width: 400px;
border: 1px solid grey;
background-color: grey;
}
#mycontent {
height: 100px;
width: 100px;
border: 1px solid blue;
text-align: left;
}
.centered {
display: block;
text-align: center;
margin: 0 auto;
}
#container .centered {
display: inline-block;
float: none;
vertical-align: middle;
}
JS:
$("#mybutton").on("click",function() {
$("#mycontent").removeClass("centered");
});