I am trying to move a div to the center of the parent div when the link is clicked.
I currently have 3 links and they correspond to 3 divs. When you click on a link, the div to which it corresponds increases (using css transitions). So far, it works well. The right link increments the right div.
After the div has been enlarged (to select it), I need the div to move to the center, and I need the div that was already in the center to take another place. This is what I am trying to achieve. I tried to use the jQuery append, prepend, animateand use closest, but I'm not sure how to get the div to move to the center and the div in the center to move to the nearest place.
I hope this makes sense so far. I found this script link (from a question about SO) and it moves divs, but this is not entirely correct.
Here is my HTML structure:
<div class="test">
<div class="test-links">
<ul>
<li><a data-target=".ecommerce" href="#">Ecommerce</a></li>
<li><a data-target=".cloud" href="#">Cloud</a></li>
<li><a data-target=".amazon" href="#">Amazon</a></li>
</ul>
</div>
<div class="test-slider">
<div class="test-slide ecommerce">
Ecommerce
</div>
<div class="test-slide cloud">
Cloud
</div>
<div class="test-slide amazon">
Amazon
</div>
</div>
</div>
This is the corresponding jQuery:
$(document).ready(function() {
$(".test-links a").click(function() {
var $target = $($(this).data('target'));
$(".test-slide").not($target).removeClass('active');
$target.addClass('active');
return false
});
});
Here is a link to a full working example.