Ok I have a fixed nav side bar that I have three icons. When an icon is clicked a div (hidden with a negative margin) will slide out. When the button is clicked again the displayed div will hide (via slide animation). This action will be repeated for the other two icons.
I realize there are many different ways to execute this, and there is a lot of supporting documentation out there with varying opinions. I have tried declaring the action via .click with .animate({"left": "+=56px"},"slow") & I have also wrote functions to fire onclick. What I'm realizing is that I can easily make this simple task far more complex than it needs to be.
Any suggestions of the cleanest way to execute this?
Edit: Thanks everyone for their input. Toggle, while it is minimalist in nature doesn't go from left to right. The script I ended up using was:
<?// Toolbar ?>
<div id="toolbar">
<img src="images/balihooGreyLogo.png" class="logo"/>
<a href="#" class="textIcon" title="Edit Copy"><img src="images/textIcon.png" border="0"/></a>
<a href="#" class="locationIcon"><img src="images/locationIcon.png" border="0"/></a>
<a href="#" class="mediaIcon"><img src="images/mediaIcon.png" border="0"/></a>
<a href="#" class="save">SAVE</a>
<a href="#" class="export">EXPORT</a>
</div>
<?// Text Input Slideout Box?>
<div class="textInput">
<h1>Email Copy</h1>
</div>
<script>
$('.textIcon').click(function () {
$('.textInput').slideToggleWidth();
});
jQuery.fn.extend({
slideRight: function() {
return this.each(function() {
$(this).animate({width: 'show'});
});
},
slideLeft: function() {
return this.each(function() {
$(this).animate({width: 'hide'});
});
},
slideToggleWidth: function() {
return this.each(function() {
var el = $(this);
if (el.css('display') == 'none') {
el.slideRight();
} else {
el.slideLeft();
}
});
}
});
</script>