- MooTools - Fx.Events
- MooTools - Fx.Options
- MooTools - Fx.Morph
- MooTools - Fx.Tween
- MooTools - Fx.Slide
- MooTools - Fx.Element
- MooTools - Classes
- MooTools - Tabbed Content
- MooTools - Tooltips
- MooTools - Accordion
- MooTools - Sortables
- MooTools - Sliders
- MooTools - Periodicals
- MooTools - Regular Expression
- MooTools - Drag and Drop
- MooTools - Input Filtering
- MooTools - Style Properties
- MooTools - DOM Manipulations
- MooTools - Event Handling
- MooTools - Functions
- MooTools - Using Arrays
- MooTools - Selectors
- MooTools - Program Structure
- MooTools - Installation
- MooTools - Introduction
- MooTools - Home
MooTools Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
MooTools - Tabbed Content
Tabbed content means the content that is present in the tabbed area and that content is related to the pst items. Whenever we apply any actions pke hover or cpck to the pst item, the immediate reaction will create an effect on the tabbed content.
Let us discuss more about tabs.
Creating Simple Tabs
Creating simple menu tabs helps you to explore additional information when you hover over a pst item. First, create an unordered pst with items, then create spans, each one corresponding to the one pst item. Let us take a look at the following HTML code.
Script
<!-- here is our menu --> <ul id = "tabs"> <p id = "one">One</p> <p id = "two">Two</p> <p id = "three">Three</p> <p id = "four">Four</p> </ul> <!-- and here are our content spans --> <span id = "contentone" class = "hidden">content for one</span> <span id = "contenttwo" class = "hidden">content for two</span> <span id = "contentthree" class = "hidden">content for three</span> <span id = "contentfour" class = "hidden">content for four</span>
Let us provide some basic support to the above HTML code using CSS that helps in hiding the data. Take a look at the following code.
.hidden { display: none; }
Let us now write a MooTools code that exhibits the tab functionapty. Take a look at the following code.
Example Snippet
//here are our functions to change the styles var showFunction = function() { this.setStyle( display , block ); } var hideFunction = function() { this.setStyle( display , none ); } window.addEvent( domready , function() { //here we turn our content elements into vars var elOne = $( contentone ); var elTwo = $( contenttwo ); var elThree = $( contentthree ); var elFour = $( contentfour ); //add the events to the tabs $( one ).addEvents({ //set up the events types //and bind the function with the variable to pass mouseenter : showFunction.bind(elOne), mouseleave : hideFunction.bind(elOne) }); $( two ).addEvents({ mouseenter : showFunction.bind(elTwo), mouseleave : hideFunction.bind(elTwo) }); $( three ).addEvents({ mouseenter : showFunction.bind(elThree), mouseleave : hideFunction.bind(elThree) }); $( four ).addEvents({ mouseenter : showFunction.bind(elFour), mouseleave : hideFunction.bind(elFour) }); });
On combining the above codes, you will get the proper functionapty.
Example
<!DOCTYPE html> <html> <head> <style> .hidden { display: none; } </style> <script type = "text/javascript" src = "MooTools-Core-1.6.0.js"></script> <script type = "text/javascript"> //here are our functions to change the styles var showFunction = function() { this.setStyle( display , block ); } var hideFunction = function() { this.setStyle( display , none ); } window.addEvent( domready , function() { //here we turn our content elements into vars var elOne = $( contentone ); var elTwo = $( contenttwo ); var elThree = $( contentthree ); var elFour = $( contentfour ); //add the events to the tabs $( one ).addEvents({ //set up the events types //and bind the function with the variable to pass mouseenter : showFunction.bind(elOne), mouseleave : hideFunction.bind(elOne) }); $( two ).addEvents({ mouseenter : showFunction.bind(elTwo), mouseleave : hideFunction.bind(elTwo) }); $( three ).addEvents({ mouseenter : showFunction.bind(elThree), mouseleave : hideFunction.bind(elThree) }); $( four ).addEvents({ mouseenter : showFunction.bind(elFour), mouseleave : hideFunction.bind(elFour) }); }); </script> </head> <body> <!-- here is our menu --> <ul id = "tabs"> <p id = "one">One</p> <p id = "two">Two</p> <p id = "three">Three</p> <p id = "four">Four</p> </ul> <!-- and here are our content spans --> <span id = "contentone" class = "hidden">content for one</span> <span id = "contenttwo" class = "hidden">content for two</span> <span id = "contentthree" class = "hidden">content for three</span> <span id = "contentfour" class = "hidden">content for four</span> </body> </html>
Output
Place your mouse pointer on the pst item, then you will get additional info of the respective item.
Marph Content Tabs
By extending the code, we can add some morph functionapty when our hidden content is displayed. We can achieve this by using Fx.Morph effect instead of stypng.
Take a look at the following code.
Example
<!DOCTYPE html> <html> <head> <style> .hiddenM { display: none; } </style> <script type = "text/javascript" src = "MooTools-Core-1.6.0.js"></script> <script type = "text/javascript"> var showFunction = function() { //resets all the styles before it morphs the current one $$( .hiddenM ).setStyles({ display : none , opacity : 0, background-color : #fff , font-size : 16px }); //here we start the morph and set the styles to morph to this.start({ display : block , opacity : 1, background-color : #d3715c , font-size : 31px }); } window.addEvent( domready , function() { var elOneM = $( contentoneM ); var elTwoM = $( contenttwoM ); var elThreeM = $( contentthreeM ); var elFourM = $( contentfourM ); //creat morph object elOneM = new Fx.Morph(elOneM, { pnk: cancel }); elTwoM = new Fx.Morph(elTwoM, { pnk: cancel }); elThreeM = new Fx.Morph(elThreeM, { pnk: cancel }); elFourM = new Fx.Morph(elFourM, { pnk: cancel }); $( oneM ).addEvent( cpck , showFunction.bind(elOneM)); $( twoM ).addEvent( cpck , showFunction.bind(elTwoM)); $( threeM ).addEvent( cpck , showFunction.bind(elThreeM)); $( fourM ).addEvent( cpck , showFunction.bind(elFourM)); }); </script> </head> <body> <!-- here is our menu --> <ul id = "tabs"> <p id = "oneM">One</p> <p id = "twoM">Two</p> <p id = "threeM">Three</p> <p id = "fourM">Four</p> </ul> <!-- and here are our content spans --> <span id = "contentoneM" class = "hiddenM">content for one</span> <span id = "contenttwoM" class = "hiddenM">content for two</span> <span id = "contentthreeM" class = "hiddenM">content for three</span> <span id = "contentfourM" class = "hiddenM">content for four</span> </body> </html>
Output
Cpck on any one item in the pst, then you will get additional information on tabs.
Advertisements