I've already checked out some of the links on StackOverflow, but nothing seems to help my issue. I have a small site here that has a JQuery accordion navigation in the middle of the page.
What's supposed to happen is when I click on one of the main links, the accordion should slide down and reveal the child links. Clicking on that would then slide down a div called #panel and it should bring in dynamic content. The content does get loaded, but the panel does not slide down. If I remove the Javascript for the dynamic content, the panel animation does work.
So obviously, there's a conflict here, but I'm not sure what it might be to cure it. Already tried adding evt.preventDefault(); to my click functions, but to no avail. Here's the code for the opening and closing of the panels, which I might add is the second instance of a script I tried to accomplish this:
//Opening and closing the top bar
var topBarHeight = jQuery('#page-con').height();
var topBarMargin = -topBarHeight - 1;
var topBarOpen = false;
function topBarContentSizeCheck(){
topBarHeight = jQuery('#page-con').height();
if(topBarOpen==false){
jQuery('#panel').css({
height: 0
});
}
else{
jQuery('#panel').css({
height: topBarHeight
});
}
}
jQuery('#panel').css({
height: 0
});
jQuery('#nav-main ul ul li a').click(function(evt){
var href = jQuery(this).attr('href');
if(href=="#panel"){
if(topBarOpen==false){
topBarOpen = true;
jQuery('#panel').animate({
height: topBarHeight,
useTranslate3d: true
});
}
else{
topBarOpen = false;
jQuery('#panel').animate({
height: 0,
useTranslate3d: true
});
jQuery('html,body').animate({
scrollTop: 0,
useTranslate3d: true
}, 400);
}
return false;
}
});
jQuery('#closelink').click(function(evt){
evt.preventDefault();
topBarOpen = false;
jQuery('#panel').animate({
height: 0
});
jQuery('html,body').animate({
scrollTop: 0
}, 400);
return false;
});
</script>
And then the code to load the dynamic content (much smaller):
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery.ajaxSetup({cache:false});
jQuery('#nav-main ul li a').click(function(){
var post_url = $(this).attr("href");
var post_id = $(this).attr("rel");
jQuery("#page-con").html("loading...");
jQuery("#page-con").load(post_url);
window.location.hash = post_id;
return false;
});
});
</script>
Any ideas on how to make the two scripts play nice?
* UPDATE *
So I decided to combine the two click functions as one. It kind of worked but not completely. The panel now comes down but the text is not loading into the #page-con div. There's nothing in console saying this. It's even listing that it does make the proper call to the server. Here's the new code.
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery.ajaxSetup({cache:false});
jQuery(".btn-slide").click(function(){
var post_id = jQuery(this).attr("rel")
jQuery("#page-con").html("loading...");
jQuery("#page-con").load("http://upsilon.lunariffic.com/~swstr0/swsg-ajax/",{id:post_id});
jQuery("#panel").slideToggle("slow");
jQuery(this).toggleClass("active");
return false;
});
});
</script>