So you may have seen this post about how I came to create such a wonderful menu with no real purpose as of yet. Well that menu has been improved and can be downloaded here.
Remember that question you never asked? Well once again I’ve answered it.
To take the normal sliding menu farther I thought I should have something happen when hovering over the menu items. Novel! Well as you can see if you clicked on the link above (Sorry, can’t repost the link. Links are expensive.) the menu items have large counter parts that show up when hovered over and don’t go away until the counter part or the main item is left. What does this all mean? I DON’T KNOW but I’ll find out eventually. It’s in the cards man, it’s in the cards…
Ok so additions… For the style sheet, I added a class:
.menuItemBig { height:100px; margin-right:5px; position:absolute; width:100px; z-index:100; }
And have included a child div to the menu item:
Before
<div class="menuItem floatLeft blue">1</div>
Now
<div class="menuItem floatLeft blue"> 1 <div class="menuItemBig red">THIS IS THE BIG ITEM 1</div> </div>
I added two methods:
// // mouseenter: Find any menuItemBig within the given element and show // Reset the position of the menuItemBig element to appear // to be in the middle of the parent element // mouseleave: Hide the child menuItemBig // function setOnHoverForMenuItems(items) { jQuery(items) .each ( function () { jQuery(this).mouseenter ( function() { //Why the positioning? I wanted the child div to show up in the // middle of the parent div which is done by putting the child's left side // to half of the width of the parent over from the parent's left side var parentPosition = jQuery(this).position(); var bigItems = jQuery(this).children(".menuItemBig"); bigItems.css({ left: parentPosition.left - (jQuery(this).width() /2), top: parentPosition.top + 10 }); bigItems.show(); } ); jQuery(this).mouseleave ( function() { jQuery(this).children(".menuItemBig").hide(); } ); } ); }
Why not hover? *EDIT* It should be hover. Turns out an issue I was having with hover was not actually an issue with it… *END EDIT*
The other method I added was a simple one:
// // Used to find any element of menuItemBig // function hideAllBigItems(bigItemParentItems) { jQuery(bigItemParentItems).children(".menuItemBig").hide(); }
And where did I use these? I appended them to the setChildrenDivs method:
function setChildrenDivs(mainHolder) { var menuItems = getMenuItems(mainHolder); for (var loopCounter = 0; loopCounter < menuItems.length; loopCounter++) { if(loopCounter > maximumToShow - 1) { jQuery(menuItems[loopCounter]).hide(); } } setPager(jQuery(mainHolder).children(".leftPager"), getLastVisible, getNextInLineBack); setPager(jQuery(mainHolder).children(".rightPager"),getFirstVisible, getNextInLineFront); setOnHoverForMenuItems(menuItems); hideAllBigItems(menuItems); }
So in all, this didn’t take much at all, thanks to mouseleave. Next up… not sure. No idea if I will take this any further.