Mootools effect with jQuery (jCow?)
in: Scripts
Mootools.net homepage features a very cool main sections navigation where the content slides to reveal more information. I wanted to accomplish something similar but do it in a way that doesn’t require me to use the mootools library (no offense, I just use jQuery more.) The information below is in no way optimized to be used but is currently a rough draft.
The setup
I created three div tags that will slide open to reveal more information, but at the same time shrink the inactive div tags. So below is the code I used for the HTML:
<div id="accordian"> <div id="blue"></div> <div id="green"></div> <div id="purple"></div> </div>
‘accordian’ has a set width to hold all three Div elements. Each div inside of ‘accordian’ contains both onmouseover and onmouseout actions, onmouseout being just the same function whereas (currently) each onmouseover activates individual functions for each div.
Here’s an extract from the JavaScript used to manipulate each Div, in this example we are manipulating the div with an id of ‘blue’:
function selectBlue(){
stopAll();
$("#blue").animate({width: "194px"});
$("#green").animate({width: "132px"});
$("#purple").animate({width: "133px"});
}
As you can see, I’m using the standard .animate function in jQuery to change the width of all three div tags. Blue, being the one we hovered over, gets extended to 194 pixels in width and the other two to 132 and 133 respectively. You would want to calculate the sizes to match up with the outer div (in this case, accordian.) ’setopAll’ refers to a function that stops all animations on all three div tags that may be present.
You can view a live demo, or download the source. I will be trying to create a better formed script that will be a little easier to use.











posted on May 9, 2008
No comment