Alright, this is a bit hard to explain, and therefore a bit hard to search for, so please forgive me if it’s been asked before. I’ll be thorough in my explanation.
I have a web page with a varying number of icons. When the user clicks on an icon, it should show the content related to that icon within a DIV. Here’s where it gets tricky. No matter which icon a user clicks, the content should load in to the same DIV. However, only content for one icon should be visible at a time. So if the content for “A” is loaded, and the user clicks on “B”, the content for “A” should fade out and be replaced with content “B” fading in, same thing with “C,” “D,” etc. (probably up to a maximum of about 5). The content can vary widely in size, so the containing DIV for the content needs to animate its height to adjust to the current content.
Where I’m stuck is the animation. I’ve figured out how to hide and show different content basically by setting display: none;” and display: block; on the different content sections based on where the user clicks, but I can’t figure out how to get any kind of animation going.
I’m open to using a pre-made script, but remember that icons and content area are in separate wrappers, so a normal jQuery tab script or accordion script isn’t going to work.
Here’s my scirpt so far:
$(document).ready(function() {
$(".heading").click(function(event) {
// remove active class from previous, add to current
$(".hidden.active").removeClass("active");
$(".hidden." + activeContent).addClass("active");
});
});
CSS for .hidden and .active:
.hidden {
display: none;
}
.hidden.active{
display: block !important;
}
Anything can be modified if necessary, but not the fact that they’re in separate wrappers.
Thanks.
Take a look at this jsFiddle; is something like this what you are looking to do?
HTML
JavaScript
You could also replace fadeOut() and fadeIn() with slideUp() and slideDown() respectively to achieve different animation effects.
I hope this helps!