as4s1n
New Member
- Messages
- 174
- Reaction score
- 4
- Points
- 0
JQuery sliding menu - Remember which root a link that was clicked was in
Hello,
I am working on a jQuery sliding menu on my site. It is working just fine, although, when someone clicks on a link to go to a new page regardless of which page they go to it always expands the first root div (which is what I told it to do if it is the first time a page is being loaded). What I want it to do is for people to click on a link and when the page reloads and that root would still be expanded. I would guess that you would create a variable that stored the data of which one and it would use that, but I don't know how to get which.
Here is a link to a live site.
Here is my javascript:
If you need it here is the HTML
Note: For some reason my stylesheet doesn't always work with this little demo I made, so if it comes out as just text refresh the page.
Hello,
I am working on a jQuery sliding menu on my site. It is working just fine, although, when someone clicks on a link to go to a new page regardless of which page they go to it always expands the first root div (which is what I told it to do if it is the first time a page is being loaded). What I want it to do is for people to click on a link and when the page reloads and that root would still be expanded. I would guess that you would create a variable that stored the data of which one and it would use that, but I don't know how to get which.
Here is a link to a live site.
Here is my javascript:
Code:
$(document).ready(function() {
$(".menu .menuItemHeader").next().hide(); // Hide all when page loads
$(".menu .menuItemHeader:first").next().slideDown('fast'); // Show the first when page loads
$(".menu div").click(expandMenuItem); // Expand item that was clicked
$(".menuExpand div").click(changePage); // Move to page depending on item clicked
});
function changePage() {
var URL = $(this).children().attr("href");
window.location = URL;
return false;
}
function expandMenuItem() {
if($(this).next().is(":hidden")) {
$(".menu .menuItemHeader").next().slideUp('normal');
$(this).next().slideDown('normal');
}
}
If you need it here is the HTML
HTML:
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="collapseMenu.js"></script>
<link rel="stylesheet" type="text/css" href="../CSS/menu.css" />
<div class="menu">
<div class="menuHeader">
<h3>Navigation</h3>
</div>
<div class="menuItems">
<div class="menuItemHeader">Root 1</div>
<div class="menuSection">
<div class="menuExpand"><a href="#">Child 1</a></div>
</div>
<div class="menuItemHeader">Root 2</div>
<div class="menuSection">
<div class="menuExpand"><a href="#">Child 1</a></div>
<div class="menuExpand"><a href="#">Child 2</a></div>
<div class="menuExpand"><a href="#">Child 3</a></div>
</div>
<div class="menuItemHeader">Root 3</div>
<div class="menuSection">
<div class="menuExpand"><a href="#">Child 1</a></div>
<div class="menuExpand"><a href="#">Child 2</a></div>
</div>
</div>
<div class="menuFooter"> </div>
</div>
Note: For some reason my stylesheet doesn't always work with this little demo I made, so if it comes out as just text refresh the page.
Last edited: