I have been using this code here:
$(document).ready(function(){
$('a[href*=#]').bind('click', function(){
var $href = $(this).attr('href')
$('html,body').animate({scrollTop: $($(this).attr('href')).offset().top}, 1200, 'easeInOutExpo');
return false;
});
$(".category-slider-trigger").click(function(e){
e.preventDefault;
$this = $(this);
var isVisible = $this.next().is(":visible");
$(".category-slider-content").stop(true,true).slideDown('slow');
$(".trigger-symbol").attr('src', '/images/plus.png');
if (!isVisible) {
$this.find(".trigger-symbol").attr('src', '/images/minus.png');
$this.next().stop(true,true).slideUp('slow');
}
return false;
});
});
On this html:
<div class="category-slider-content">
<div class="grid_1"> </div>
<div class="grid_10 category-filter-area">
<a class="stock-latest-additions" href="/stock/latest-additions">Latest additions</a>
<?
foreach ($stock_categories as $cat) {
echo("<h2 class=\"stock-category-title\">".$cat['title'].":</h2>");
echo("<ul class=\"stock-categories-list\">");
foreach ($cat['sub_categories'] as $sub_cat) {
echo("<li><a href=\"/stock/".$util->formatCategoryParam($sub_cat['title'])."\">".$sub_cat['title']."</a></li>");
}
echo("</ul>");
echo("<div class=\"clear\"></div>");
}
?>
</div>
<div class="grid_1"> </div>
Show/Hide Categories
But I’m having a problem with the functionality. When the link is clicked, the categories reveal themselves from the top and slide down, but it won’t slide back up.
I’ve set up a jsFiddle here… http://jsfiddle.net/CwP8w/
Any suggestions?
Thanks,
R
Working demo http://jsfiddle.net/GmpZb/3/
Good API: http://api.jquery.com/slideToggle/
you can avoid the full isVisible logic if you where only doing that for show and hide by using slideToggle.
This will help. B-)
code changed
full code