Hey there! I've been struggling with a simple issue for quite some time now. I have a menu with a toggle function using plus/minus signs, but it only seems to work on the homepage and not on any other pages. Here's the code snippet:
$(document).ready(function(){
$('.gh-gallink').toggle(
function() {
$('.gallery_container').animate({
marginTop: "x",
}, 1000);
$('.jquerycssmenu ul li ul').animate({
marginTop: "x",
}, 100);
$('.jquerycssmenu ul li ul li a').animate({
height: "x",
}, 100);
$('#main').animate({
marginTop: "x",
}, 1000);
$(this).text('+');
}, function() {
$('.gallery_container').animate({
marginTop: "x",
}, 1000);
$('.jquerycssmenu ul li ul').animate({
marginTop: "x",
}, 100);
$('.jquerycssmenu ul li ul li a').animate({
height: "x",
}, 100);
$('#main').animate({
marginTop: "x",
}, 1000);
$(this).text('-');
});
});
The menu functions correctly on the main page, but doesn't seem to work elsewhere on the site. I even tried changing "$(document)" to "jQuery(Document)" and disabling all plugins, but the issue persists. The code is in the header.php file of my website. Any suggestions would be greatly appreciated!
Here's the HTML for the toggle button:
<div class="gallerylink">
<a href="#" class="gh-gallink">
-
</a>
</div>
In an update, upon removing another script that scrolls to an anchor when clicked, the toggle menu works fine. However, I would like both scripts to work simultaneously. Here's the scrolling script:
// When the Document Object Model is ready
jQuery(document).ready(function(){
// 'catTopPosition' is the amount of pixels #invisiblebox
// is from the top of the document
var catTopPosition = jQuery('#invisiblebox').offset().top;
// When #scroll is clicked
jQuery('#scroll, #scrolls').click(function(){
// Scroll down to 'catTopPosition'
jQuery('html, body').animate({scrollTop:catTopPosition}, 'slow');
// Stop the link from acting like a normal anchor link
return false;
});
});
Clicking on #scrolls or #scroll should scroll back up to anchor "#invisiblebox". Not sure why this conflicts with the toggle menu. Would appreciate any insights on how to make both scripts run smoothly together.