I’m trying to have two elements slide in on a single click. I’d like the first element (an img) to slide in from the left and the other element (a p tag) to slide in from the right on click of a button (an li). Then, when another button is clicked, I’d like the first two elements to fade away and the next two elements (corresponding to the button clicked) slide in.
Is there a way to loop through these so they are always sliding in.
$(‘#nav-button-1’).click(function() {
$('#people-2').hide();
$('#people-3').hide();
$('#people-1').show();
$('.slideleft').animate({
marginLeft: '103px'
}, 1000, function() {
// Animation complete.
});
$('#slideright').animate({
marginRight: '12px'
}, 1000, function() {
// Animation complete.
});
});
Here is an example to get started.
I made a function out of your original JS
Here is a method that is called on the button presses. It takes in the ID of the wrapper where the animated items are contained and eventually calls the above method.
Lastly, these are the handlers for the buttons.
jsfiddle