MooTools – Tabbed Content ”; Previous Next Tabbed content means the content that is present in the tabbed area and that content is related to the list items. Whenever we apply any actions like hover or click to the list 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 list item. First, create an unordered list with items, then create divs, each one corresponding to the one list item. Let us take a look at the following HTML code. Script <!– here is our menu –> <ul id = “tabs”> <li id = “one”>One</li> <li id = “two”>Two</li> <li id = “three”>Three</li> <li id = “four”>Four</li> </ul> <!– and here are our content divs –> <div id = “contentone” class = “hidden”>content for one</div> <div id = “contenttwo” class = “hidden”>content for two</div> <div id = “contentthree” class = “hidden”>content for three</div> <div id = “contentfour” class = “hidden”>content for four</div> 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 functionality. 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 functionality. 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”> <li id = “one”>One</li> <li id = “two”>Two</li> <li id = “three”>Three</li> <li id = “four”>Four</li> </ul> <!– and here are our content divs –> <div id = “contentone” class = “hidden”>content for one</div> <div id = “contenttwo” class = “hidden”>content for two</div> <div id = “contentthree” class = “hidden”>content for three</div> <div id = “contentfour” class = “hidden”>content for four</div> </body> </html> Output Place your mouse pointer on the list item, then you will get additional info of the respective item. Marph Content Tabs By extending the code, we can add some morph functionality when our hidden content is displayed. We can achieve this by using Fx.Morph effect instead of styling. 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, { link: ”cancel” }); elTwoM = new Fx.Morph(elTwoM, { link: ”cancel” }); elThreeM = new Fx.Morph(elThreeM, { link: ”cancel” }); elFourM = new Fx.Morph(elFourM, { link: ”cancel” }); $(”oneM”).addEvent(”click”, showFunction.bind(elOneM)); $(”twoM”).addEvent(”click”, showFunction.bind(elTwoM)); $(”threeM”).addEvent(”click”, showFunction.bind(elThreeM)); $(”fourM”).addEvent(”click”, showFunction.bind(elFourM)); }); </script> </head> <body> <!– here is our menu –> <ul id = “tabs”> <li id = “oneM”>One</li> <li id = “twoM”>Two</li> <li id = “threeM”>Three</li> <li id = “fourM”>Four</li> </ul> <!– and here are our content divs –> <div id = “contentoneM” class = “hiddenM”>content for one</div> <div id = “contenttwoM” class = “hiddenM”>content for two</div> <div id = “contentthreeM” class = “hiddenM”>content for three</div> <div id = “contentfourM” class = “hiddenM”>content for four</div> </body> </html> Output Click on any one item in the list, then you will get additional information on tabs. Print Page Previous Next Advertisements ”;
Category: mootools
MooTools – Useful Resources
MooTools – Useful Resources ”; Previous Next The following resources contain additional information on MooTools. Please use them to get more in-depth knowledge on this. Useful Video Courses Web Development from Course – Tools and Resources 14 Lectures 54 mins Laurence Svekis More Detail Ultimate Persuasion Strategies! – Influence Tools & Skills 13 Lectures 2 hours Prof. Paul Cline, Ed.D More Detail Digital Tools for Customer Acquisition, Conversion, And Retention for SME’s 20 Lectures 1 hours Chinny Uju Nwokedi More Detail 9 FREE Best Digital Marketing Tools That Will Blow Your Mind Featured 11 Lectures 50 mins Being Commerce More Detail 10 Killer Negotiating Tools That Will Turn You Into A Master Negotiator 11 Lectures 30 mins Ken Burke More Detail Set Up an Electronics Home Lab Tools and Equipment 59 Lectures 4 hours Ashraf Said More Detail Print Page Previous Next Advertisements ”;
MooTools – Fx.Slide
MooTools – Fx.Slide ”; Previous Next Fx.Slides is an option that lets you display the content by sliding into view. It is very simple but enhances the look of your UI. Let us discuss about creating and initializing an Fx.Slide, its options, and methods. First, we will initialize the Fx.Slide class with a user-defined instance. For that, we have to create and select an HTML element. After that, we will apply CSS to these elements. Finally, we will initiate a new instance of Fx.Slide with our element variable. Fx.Slide Options There are only two Fx.Slide options — mode and wrapper. Mode Mode gives you two choices, ‘vertical’ or ‘horizontal’. Vertical reveals from top to bottom and horizontal reveals from left to right. There are no options to go from bottom to top or from right to left, tho I understand that hacking the class itself to accomplish this is relatively simple. In my opinion, it’s an option I would like to see standard, and if anyone has hacked the class to allow this options, please drop us a note. Wrapper By default, Fx.Slide throws a wrapper around your slide element, giving it ‘overflow’: ‘hidden’. Wrapper allows you to set another element as the wrapper. Like I said above, I am not clear on where this would come in handy and would be interested to hear any thoughts (thanks to horseweapon at mooforum.net for helping me clear this up). Fx.Slide Methods Fx.Slide also features many methods for showing and hiding your element. slideIn() As the name implies, this method will fire the start event and reveal your element. slideOut() Slides your element back to the hidden state. toggle() This will either slide the element in or out, depending on its current state. Very useful method to add to click events. hide() This will hide the element without a slide effect. show() This will show the element without a slide effect. Fx.Slide Shortcuts The Fx.Slide class also provides some handy shortcuts for adding effects to an element. set(‘slide’) Instead of initiating a new class, you can create a new instance if you ’set’ slide on an element. Syntax slideElement.set(”slide”); setting options You can even set options with the shortcut − Syntax slideElement.set(”slide”, {duration: 1250}); slide() Once the slide is .set(), you can initiate it with the .slide() method. Syntax slideElement.slide(”in”); .slide will accept − ‘in’ ‘out’ ‘toggle’ ’show’ ‘hide’ …each corresponding to the methods above. Example Let us take an example that explains about Fx.Slide. Take a look into the following code. <!DOCTYPE html> <html> <head> <style> .ind { width: 200px; padding: 10px; background-color: #87AEE1; font-weight: bold; border-bottom: 1px solid white; } .slide { margin: 20px 0; padding: 10px; width: 200px; background-color: #F9E79F; } #slide_wrap { padding: 30px; background-color: #D47000; } </style> <script type = “text/javascript” src = “MooTools-Core-1.6.0.js”></script> <script type = “text/javascript” src = “MooTools-More-1.6.0.js”></script> <script type = “text/javascript”> window.addEvent(”domready”, function() { var slideElement = $(”slideA”); var slideVar = new Fx.Slide(slideElement, { //Fx.Slide Options mode: ”horizontal”, //default is ”vertical” //wrapper: this.element, //default is this.element //Fx Options link: ”cancel”, transition: ”elastic:out”, duration: ”long”, //Fx Events onStart: function(){ $(”start”).highlight(“#EBCC22″); }, onCancel: function(){ $(”cancel”).highlight(“#EBCC22″); }, onComplete: function(){ $(”complete”).highlight(“#EBCC22″); } }).hide().show().hide(); //note, .hide and .show do not fire events $(”openA”).addEvent(”click”, function(){ slideVar.slideIn(); }); $(”closeA”).addEvent(”click”, function(){ slideVar.slideOut(); }); //EXAMPLE B var slideElementB = $(”slideB”); var slideVarB = new Fx.Slide(slideElementB, { //Fx.Slide Options mode: ”vertical”, //default is ”vertical” link: ”chain”, //Fx Events onStart: function(){ $(”start”).highlight(“#EBCC22″); }, onCancel: function(){ $(”cancel”).highlight(“#EBCC22″); }, onComplete: function(){ $(”complete”).highlight(“#EBCC22″); } }); $(”openB”).addEvent(”click”, function(){ slideVarB.slideIn(); }); $(”closeB”).addEvent(”click”, function(){ slideVarB.slideOut(); }); }); </script> </head> <body> <div id = “start” class = “ind”>Start</div> <div id = “cancel” class = “ind”>Cancel</div> <div id = “complete” class = “ind”>Complete</div> <button id = “openA”>open A</button> <button id = “closeA”>close A</button> <div id = “slideA” class = “slide”>Here is some content – A. Notice the delay before onComplete fires. This is due to the transition effect, the onComplete will not fire until the slide element stops “elasticing.” Also, notice that if you click back and forth, it will “cancel” the previous call and give the new one priority.</div> <button id = “openB”>open B</button> <button id = “closeB”>close B</button> <div id = “slideB” class = “slide”>Here is some content – B. Notice how if you click me multiple times quickly I “chain” the events. This slide is set up with the option “link: ”chain””</div> </body> </html> Output Click on the buttons — openA, closeA, openB, and closeB. Observe the changes, effect, and event notification on the indicators. Print Page Previous Next Advertisements ”;
MooTools – Accordion
MooTools – Accordion ”; Previous Next Accordion is the most popular plugin that MooTools provides. It helps in hiding and revealing the data. Let us discuss more about it. Creating new accordion The basic elements that an accordion requires are pairs of toggles and their contents. Let us create pairs of headings and contents of the html. <h3 class = “togglers”>Toggle 1</h3> <p class = “elements”>Here is the content of toggle 1</p> <h3 class = “togglers”>Toggle 2</h3> <p class = “elements”>Here is the content of toggle 2</p> Take a look at the following syntax to understand how to build an accordion based on the above HTML structure. Syntax var toggles = $$(”.togglers”); var content = $$(”.elements”); var AccordionObject = new Fx.Accordion(toggles, content); Example Let us take an example that defines the basic functionality of Accordion. Take a look at the following code. <!DOCTYPE html> <html> <head> <style> .togglers { padding: 4px 8px; color: #fff; cursor: pointer; list-style: none; width: 300px; background-color: #222; border: 1px solid; } </style> <script type = “text/javascript” src = “MooTools-Core-1.6.0.js”></script> <script type = “text/javascript” src = “MooTools-More-1.6.0.js”></script> <script type = “text/javascript”> window.addEvent(”domready”, function() { var toggles = $$(”.togglers”); var content = $$(”.elements”); var AccordionObject = new Fx.Accordion(toggles, content); }); </script> </head> <body> <h3 class = “togglers”>Toggle 1</h3> <p class = “elements”>Here is the content of toggle 1</p> <h3 class = “togglers”>Toggle 2</h3> <p class = “elements”>Here is the content of toggle 2</p> <h3 class = “togglers”>Toggle 3</h3> <p class = “elements”>Here is the content of toggle 3</p> </body> </html> You will receive the following output − Output Accordion Options Accordion provides tremendous features. These features help in tweaking the options to give customized output. display This option determines which element shows on page load. The default is set to 0, so the first element shows. To set another element, just put in another integer that corresponds with its index. Unlike “show”, display will transition the element open. Syntax var AccordionObject = new Accordion(toggles, content { display: 0 //default is 0 }); show Much like “display,” show determines which element will be open when the page loads, but instead of a transition, “show” will just make the content display on load without any transition. Syntax var AccordionObject = new Accordion(toggles, content { show: 0 //default is 0 }); height When set to true, a height transition effect will take place when switching between displayed elements.. This is the standard accordion setting you see above. Syntax var AccordionObject = new Accordion(toggles, content { height: true //default is true }); width This works the same like the height option. However, instead of transitioning the height to show the content, this helps in transitioning of the width. If you use “width” with a standard setup, like we used above, then the space between the title toggle will stay the same, based on the height of the content. The “content” div will then transition from left to right to display in that space. Syntax var AccordionObject = new Accordion(toggles, content { width: false //default is false }); opacity This option determines whether or not to show an opacity transition effect when you hide or display some content. Since we are using the default options above, you can see the effect there. Syntax var AccordionObject = new Accordion(toggles, content { opacity: true //default is true }); fixedHeight To set a fixed height, you need to fix an integer (for example, you could put 100 for the content 100px tall). This should be used with some kind of CSS overflow property if you are planning on having a fixed height smaller than the contents natural height. Syntax var AccordionObject = new Accordion(toggles, content { fixedHeight: false //default is false }); fixedWidth Just like “fixedHeight” above, this will set the width if you give this option an integer. Syntax var AccordionObject = new Accordion(toggles, content { fixedWidth: false //default is false }); alwaysHide This option lets you add a toggle control to the titles. With this set to true, when you click on an open content title, the content element will close automatically without opening anything else. You can see the execution in the following example. Syntax var AccordionObject = new Accordion(toggles, content { alwaysHide: false //default is false }); Accordion Events These events allow you to create your functionality for every action of Accordion. onActive This will execute when you toggle open an element. It will pass the toggle control element and the content element that is opening and also the parameters. Syntax var AccordionObject = new Accordion(toggles, content { onActive: function(toggler, element) { toggler.highlight(”#76C83D”); //green element.highlight(”#76C83D”); } }); onBackground This executes when an element starts to hide and passes all other elements that are closing, but not opening. Syntax var AccordionObject = new Accordion(toggles, content { onBackground: function(toggler, element) { toggler.highlight(”#DC4F4D”); //red element.highlight(”#DC4F4D”); } }); onComplete This is your standard onComplete event. It passes a variable containing the content element. Syntax var AccordionObject = new Accordion(toggles, content { onComplete: function(one, two, three, four){ one.highlight(”#5D80C8”); //blue two.highlight(”#5D80C8”); three.highlight(”#5D80C8”); four.highlight(”#5D80C8”); } }); Accordion Methods These methods help you create and manipulate Accordion Sections. addSection() With this method, you can add a section (a toggle/content element pair). It works like many of the other methods we have seen. First refer to the accordion object, use .addSection, then you can call the id of the title, the id of the content, and finally state what position you want the new content to appear in (0 being the first spot). Syntax AccordionObject.addSection(”togglersID”, ”elementsID”, 2); Note − When you add a section like this, though it will show up in the spot of index 2, the actual index will be be +1 the last index. So if you have 5 items in your array (0-4) and you add a 6th, its index would be 5 regardless of where you add it with .addSection(); display() This lets you open a given element. You can select the element by its index (so if you have added
MooTools – Sortables
MooTools – Sortables ”; Previous Next Sortables is an advanced feature in web development and can really open up the options with your user interface designs. It also includes a great function called “serialize” that manages a list of element ids and is useful for server side scripting. Creating a New Sortable Object First, we send the list of items to a variable. If you want an array of the list of items, then assign all collection to a variable. And, finally pass that variable to a sortable constructor. Take a look at the following syntax to create a sortable object. Syntax var sortableListsArray = $$(”#listA, #listB”); var sortableLists = new Sortables(sortableListsArray); The following is the HTML code for the syntax. Syntax <ul id = “listA”> <li>Item A1</li> <li>Item A2</li> <li>Item A3</li> <li>Item A4</li> </ul> <ul id = “listB”> <li>Item B1</li> <li>Item B2</li <li>Item B3</li> <li>Item B4</li> </ul> Sortables Option Sortable provides different options to customize the sortable object. Let us discuss the options. Constrain This option determines whether the list elements can jump between uls within the sortable object. For example, if you have two uls in the sortable object, you can “constrain” the list items to their parent ul by setting “constrain: true“. Take a look at the following syntax for setting constrain. Syntax var sortableLists = new Sortables(sortableListsArray, { constrain: true //false is default }); Clone This option helps you to create a clone element under your cursor. It helps in sorting the list elements. Take a look at the following syntax for clone. Syntax var sortableLists = new Sortables(sortableListsArray, { clone: true //false is default }); Handle Handle is an option that accepts an element to act as the drag handle. This is useful whenever you want your list items selectable or you want any actions in your list. If you are not providing any variable it will be considered as false by default. Take a look at the following syntax for using handle. Syntax var handleElements = $$(”.handlesClass”); var sortableLists = new Sortables(sortableListsArray, { handle: handleElements //false is default }); Opacity This option lets you adjust the sort element. If you use a clone, opacity affects the element that sorts. Syntax var sortableLists = new Sortables(sortableListsArray, { opacity: 1 //default is 1 }); Revert This option accepts either “false” or any Fx option. If you set Fx option within revert, it will create an effect for the sorted element to settle into place. Take a look at the following syntax for revert. Syntax var sortableLists = new Sortables(sortableListsArray, { revert: false //this is the default }); //you can also set Fx options var sortableLists = new Sortables(sortableListsArray, { revert: { duration: 50 } }); Snap This option lets you see how many px the user will drag the mouse before the element starts following. Syntax var sortableLists = new Sortables(sortableListsArray, { snap: 10 //user will have to drag 10 px to start the list sorting }); Sortable Events Sortable provides the following events that are nice and straight forward. onStart − executes when the drag starts (once snap kicks over) onSort − executes when the items change order onComplete − executes when you drop an element in place Sortable Methods The following sortable methods are essentially functions that belong to classes − detach() With detach(), you can “detach” all the current handles, making the entire list object not sortable. This is useful for disabling sort. attach() This method will “attach” the handles to the sort items, works to enable sorting after detach(). addItems() This allows you to add new items to your sortable list. Let’s say that you have a sortable list where the user can add a new item, once you add that new item, you will need to enable sorting on that new item. removeItems() This method lets you remove the sorting capability of an item within a sortable list. This is useful when you want to lock a particular item within a specific list and not let it sort with others. addLists() Instead of just adding a new item to an existing list, you may want to add a whole new list to the sortable object. This method lets you add multiple lists, making it really easy to add more sortables. removeLists() Let us remove the lists from the sortable object. This is useful for when you want to lock a particular list in place. You can remove the list, leaving the other lists still in the object sortable, but locking the content of the removed list. serialize() All of that sorting is great, but what if you want to do something with the data? .serialize(); will return a list of the item ids as well as their order on the list. You can choose which list to get data from within the object by index number. Example The following example creates an array of div elements with numbering. Later, rearrange those by click, drag, and drop actions using mouse pointer. Take a look at the following code. <!DOCTYPE html> <html> <head> <style> #test { position: inherit; } ul#sortables { width: 300px; margin: 0; padding: 0; } li.sortme { padding: 4px 8px; color: #fff; cursor: pointer; list-style: none; width: 300px; background-color: #222; border: 1px solid; } ul#sortables li { margin: 10px 0; } </style> <script type = “text/javascript” src = “MooTools-Core-1.6.0.js”></script> <script type = “text/javascript” src = “MooTools-More-1.6.0.js”></script> <script type = “text/javascript”> window.addEvent(”domready”, function() { new Sortables($(”test”), { initialize: function(){ var step = 0; this.elements.each(function(element, i) { var color = [step, 82, 87].hsbToRgb(); element.setStyle(”background-color”, color); step = step + 35; element.setStyle(”height”, $random(40, 100)); }); } }); }); </script> </head> <body> <ul id = “test”> <li class = “sortme”>0</li> <li class = “sortme”>1</li> <li class = “sortme”>2</li> <li class = “sortme”>3</li> <li class = “sortme”>4</li> <li class = “sortme”>5</li> <li class = “sortme”>6</li> <li class = “sortme”>7</li> <li class = “sortme”>8</li> <li class = “sortme”>9</li> <li class = “sortme”>10</li> </ul> </body> </html> You will receive the following output −
MooTools – Fx.Tween
MooTools – Fx.Tween ”; Previous Next MooTools provides different FX.Tween shortcuts for different transitions such as flashy effects which translate to smooth animated transitions. Let us discuss a few methods from the Tween shortcuts. tween() This method provides smooth transitions between two style property values. Let us take an example that uses tween method to change the width of a div from 100px to 300px. Take a look at the following code. Example <!DOCTYPE html> <html> <head> <style> #body_div { width: 100px; height: 200px; background-color: #1A5276; border: 3px solid #dd97a1; } </style> <script type = “text/javascript” src = “MooTools-Core-1.6.0.js”></script> <script type = “text/javascript” src = “MooTools-More-1.6.0.js”></script> <script type = “text/javascript”> var tweenFunction = function(){ $(”body_div”).tween(”width”,”300px”); } window.addEvent(”domready”, function() { $(”tween_button”).addEvent(”click”, tweenFunction); }); </script> </head> <body> <div id = “body_div”> </div><br/> <input type = “button” id = “tween_button” value = “Set Width to 300 px”/> </body> </html> You will receive the following output − Output fade() This method adjusts the element opacity or the transparency. Let us take an example wherein, we provide a button to adjust the opacity of a div using MooTools. Take a look at the following code. Example <!DOCTYPE html> <html> <head> <style> #body_div { width: 100px; height: 200px; background-color: #1A5276; border: 3px solid #dd97a1; } </style> <script type = “text/javascript” src = “MooTools-Core-1.6.0.js”></script> <script type = “text/javascript” src = “MooTools-More-1.6.0.js”></script> <script type = “text/JavaScript”> var fadeFunction = function(){ $(”body_div”).fade(”.5”); } window.addEvent(”domready”, function() { $(”fade_button”).addEvent(”click”, fadeFunction); }); </script> </head> <body> <div id = “body_div”> </div><br/> <input type = “button” id = “fade_button” value = “fade to 50%”/> </body> </html> You will receive the following output − Output Click on the fade to 50% button to reduce the div opacity to 50%. highlight() This method highlights an element using different background colors. It contains two main functionalities of the Tween Flash. In the first functionality, Tween Flash is used to apply different background colors to elements. Once the Tween Flash sets a different background color, then it switches to another background color. This method is used to highlight an element after selection. Let us take an example to understand this method. Take a look at the following code. Example <!DOCTYPE html> <html> <head> <style> #div1 { width: 100px; height: 100px; background-color: #1A5276; border: 3px solid #dd97a1; } #div2 { width: 100px; height: 100px; background-color: #145A32; border: 3px solid #dd97a1; } </style> <script type = “text/javascript” src = “MooTools-Core-1.6.0.js”></script> <script type = “text/javascript” src = “MooTools-More-1.6.0.js”></script> <script type = “text/javascript”> var highlightFunction = function(){ $(”div1”).highlight(”#eaea16”); } var highlightChangeFunction = function(){ $(”div2”).highlight(”#eaea16”, ”#FBFCFC”); } window.addEvent(”domready”, function() { $(”div1”).addEvent(”mouseover”, highlightFunction); $(”div2”).addEvent(”mouseover”, highlightChangeFunction); }); </script> </head> <body> <div id = “div1”> </div><br/> <div id = “div2″> </div> </body> </html> You will receive the following output − Output Try to keep the mouse pointer on the colored divs and observe the changes in flash highlights. Print Page Previous Next Advertisements ”;
MooTools – Fx.Element
MooTools – Fx.Element ”; Previous Next Fx.Element allows you to add the Fx functionality to multiple dom elements on a single page. Actually Fx.Element is an extension of the Fx.Morph plugin. The only difference between Fx.Element and Fx.Morph is the syntax. In this syntax, the start({}) method is used to create an effect and the .set({}) method is used to set some styles. Take a look at the following syntax for Fx.Element. Syntax var fxElementsArray = $$(”.myElementClass”); var fxElementsObject = new Fx.Elements(fxElementsArray, { //Fx Options link: ”chain”, duration: 1000, transition: ”sine:in:out”, //Fx Events onStart: function(){ startInd.highlight(”#C3E608”); } }); start({}) and set({}) Start and set keyword structures are used to start and set styles. But in this structure, you refer to the element via the index — the first element is 0, the second is 1, and so on. Take a look at the following syntax for the Start and Set structures. Syntax //you can set your styles with .set({…}) fxElementsObject .set({ ”0”: { ”height”: 10, ”width”: 10, ”background-color”: ”#333” }, ”1”: { ”width”: 10, ”border”: ”1px dashed #333” } }); //or create a transition effect with .start({…}) fxElementsObject .start({ ”0”: { ”height”: [50, 200], ”width”: 50, ”background-color”: ”#87AEE1” }, ”1”: { ”width”: [100, 200], ”border”: ”5px dashed #333” } }); Example Let us take an example that explains the Fx.Element. Take a look at the following code. <!DOCTYPE html> <html> <head> <style> .ind { width: 200px; padding: 10px; background-color: #87AEE1; font-weight: bold; border-bottom: 1px solid white; } .myElementClass { height: 50px; width: 100px; background-color: #FFFFCC; border: 1px solid #FFFFCC; padding: 20px; } #buttons { margin: 20px 0; display: block; } </style> <script type = “text/javascript” src = “MooTools-Core-1.6.0.js”></script> <script type = “text/javascript” src = “MooTools-More-1.6.0.js”></script> <script type = “text/javascript”> var startFXElement = function(){ this.start({ ”0”: { ”height”: [50, 100], ”width”: 50, ”background-color”: ”#87AEE1” }, ”1”: { ”width”: [100, 200], ”border”: ”5px dashed #333” } }); } var startFXElementB = function(){ this.start({ ”0”: { ”width”: 300, ”background-color”: ”#333” }, ”1”: { ”width”: 300, ”border”: ”10px solid #DC1E6D” } }); } var setFXElement = function(){ this.set({ ”0”: { ”height”: 50, ”background-color”: ”#FFFFCC”, ”width”: 100 }, ”1”: { ”height”: 50, ”width”: 100, ”border”: ”none” } }); } window.addEvent(”domready”, function() { var fxElementsArray = $$(”.myElementClass”); var startInd = $(”start_ind”); var cancelInd = $(”cancel_ind”); var completeInd = $(”complete_ind”); var chainCompleteInd = $(”chain_complete_ind”); var fxElementsObject = new Fx.Elements(fxElementsArray, { //Fx Options link: ”chain”, duration: 1000, transition: ”sine:in:out”, //Fx Events onStart: function(){ startInd.highlight(”#C3E608”); }, onCancel: function(){ cancelInd.highlight(”#C3E608”); }, onComplete: function(){ completeInd.highlight(”#C3E608”); }, onChainComplete: function(){ chainCompleteInd.highlight(”#C3E608”); } }); $(”fxstart”).addEvent(”click”, startFXElement.bind(fxElementsObject)); $(”fxstartB”).addEvent(”click”, startFXElementB.bind(fxElementsObject)); $(”fxset”).addEvent(”click”, setFXElement.bind(fxElementsObject)); $(”fxpause”).addEvent(”click”, function(){ fxElementsObject.pause(); }); $(”fxresume”).addEvent(”click”, function(){ fxElementsObject.resume(); }); }); </script> </head> <body> <div id = “start_ind” class = “ind”>onStart</div> <div id = “cancel_ind” class = “ind”>onCancel</div> <div id = “complete_ind” class = “ind”>onComplete</div> <div id = “chain_complete_ind” class = “ind”>onChainComplete</div> <span id = ”buttons”> <button id = “fxstart”>Start A</button> <button id = “fxstartB”>Start B</button> <button id = “fxset”>Reset</button> <button id = “fxpause”>Pause</button> <button id = “fxresume”>Resume</button> </span> <div class = “myElementClass”>Element 0</div> <div class = “myElementClass”>Element 1</div> </body> </html> You will receive the following output − Output Print Page Previous Next Advertisements ”;
MooTools – Fx.Morph
MooTools – Fx.Morph ”; Previous Next Fx.Morph is a function provided by MooTools. It is used to create new tween for transitions between style properties. While morphing, we have to select the element with an object and then we can apply different functions to it. We also need to bind the element with a newly created tween. Let us take an example that provides three buttons on a web page. The first one is the SET button that creates an element with style properties such as height, width, and color. The second one is the MORPH button that changes the style properties of an element. The third one is the RESET button that changes all settings to the starting position. Take a look at the following code. Example <!DOCTYPE html> <html> <head> <script type = “text/javascript” src = “MooTools-Core-1.6.0.js”></script> <script type = “text/javascript” src = “MooTools-More-1.6.0.js”></script> <script type = “text/javascript”> var morphSet = function(){ this.set({ ”width”: 100, ”height”: 100, ”background-color”: ”#884EA0” }); } var morphStart = function(){ this.start({ ”width”: 200, ”height”: 200, ”background-color”: ”#d3715c” }); } var morphReset = function(){ this.set({ ”width”: 0, ”height”: 0, ”background-color”: ”#ffffff” }); } window.addEvent(”domready”, function() { var morphElement = $(”morph_element”); var morphObject = new Fx.Morph(morphElement); $(”set”).addEvent(”click”, morphSet.bind(morphObject)); $(”start”).addEvent(”click”, morphStart.bind(morphObject)); $(”reset”).addEvent(”click”, morphReset.bind(morphObject)); }); </script> </head> <body> <div id = “morph_element”> </div><br/> <input type = “button” id = “set” value = “SET”/> <input type = “button” id = “start” value = “START”/> <input type = “button” id = “reset” value = “RESET”/> </body> </html> You will receive the following output − Output Print Page Previous Next Advertisements ”;
MooTools – Tooltips
MooTools – Tooltips ”; Previous Next MooTools provides different tooltips to design custom styles and effects. In this chapter, we will learn the various options and events of tooltips, as well as a few tools that will help you add or remove tooltips from elements. Creating a New Tooltip Creating a tooltip is very simple. First, we have to create the element where we will attach the tooltip. Let us take an example that creates an anchor tag and adds that to the Tips class in the constructor. Take a look at the following code. <a id = “tooltipID” class = “tooltip_demo” title = “1st Tooltip Title” rel = “here is the default ”text” for toll tip demo” href = “http://www.tutorialspoint.com”>Tool tip _demo</a> Take a look at the code used to create tooltip. var customTips = $$(”.tooltip_demo”); var toolTips = new Tips(customTips); Example The following example explains the basic idea of Tooltips. Take a look at the following code. <!DOCTYPE html> <html> <head> <script type = “text/javascript” src = “MooTools-Core-1.6.0.js”></script> <script type = “text/javascript” src = “MooTools-More-1.6.0.js”></script> <script type = “text/javascript”> window.addEvent(”domready”, function() { var customTips = $$(”.tooltip_demo”); var toolTips = new Tips(customTips); }); </script> </head> <body> <a id = “tooltipID” class = “tooltip_demo” title = “1st Tooltip Title” rel = “here is the default ”text” for toll tip demo” href = “http://www.tutorialspoint.com”>Tool tip _demo</a> </body> </html> You will receive the following output − Output Tooltip Options There are only five options in Tips and they are all pretty self-explanatory. showDelay An integer measured in milliseconds, this will determine the delay before the tooltip shows once the user mouse onto the element. The default is set at 100. hideDelay Just like showDelay above, this integer (also measured in milliseconds) determines how long to wait before hiding the tip once the user leaves the element. The default is set at 100. className This lets you set a class name for the tooltip wrap. The default is set to Null. Offset This determines how far away from the element the tooltip will appear. ‘x’ refers to the right offset, where ‘y’ is the down offset (both relative to the cursor IF the ‘fixed’ option is set to false, otherwise the offset is relative to the original element). Default is x: 16, y: 16 Fixed This sets whether or not the tooltip will follow your mouse if you move around the element. If you set it to true, the tooltip will not move when you move your cursor, but will stay fixed relative to the original element. The default is set to false. Tooltip Events The tooltip events remain simple, like the rest of this class. There are two events — onShow and onHide, and they work as you would expect. onShow() This event executes when the tooltip appears. If you set a delay, this event will not execute until the delay is up. onHide() The tooltip hides with the execution of this event. If there is a delay, this event will not execute until the delay is up. Tooltip Methods There are two methods for tooltips — attach and detach. This lets you target a specific element and add it to a tooltip object (and thereby, inherent all the settings in that class instance) or detach a particular element. attach() To attach a new element to a tooltip object, just state the tip object, the tack on .attach();, and finally place the element selector within the brackets (). Syntax toolTips.attach(”#tooltipID3”); dettach() This method works just as the .attach method, but the outcome is completely the opposite. First, state the tip object, then add .dettach(), and finally place your element selector within (). Syntax toolTips.dettach(”#tooltipID3”); Example Let us take an example that explains tooltip. Take a look at the following code. <!DOCTYPE html> <html> <head> <style> .custom_tip .tip { background-color: #333; padding: 5px; } .custom_tip .tip-title { color: #fff; background-color: #666; font-size: 20px; padding: 5px; } .custom_tip .tip-text { color: #fff; padding: 5px; } </style> <script type = “text/javascript” src = “MooTools-Core-1.6.0.js”></script> <script type = “text/javascript” src = “MooTools-More-1.6.0.js”></script> <script type = “text/javascript”> window.addEvent(”domready”, function() { var customTips = $$(”.tooltip_demo”); var toolTips = new Tips(customTips, { showDelay: 1000, //default is 100 hideDelay: 100, //default is 100 className: ”custom_tip”, //default is null offsets: { ”x”: 100, //default is 16 ”y”: 16 //default is 16 }, fixed: false, //default is false onShow: function(toolTipElement){ toolTipElement.fade(.8); $(”show”).highlight(”#FFF504”); }, onHide: function(toolTipElement){ toolTipElement.fade(0); $(”hide”).highlight(”#FFF504”); } }); var toolTipsTwo = new Tips(”.tooltip2”, { className: ”something_else”, //default is null }); $(”tooltipID1”).store(”tip:text”, ”You can replace the href with whatever text you want.”); $(”tooltipID1”).store(”tip:title”, ”Here is a new title.”); $(”tooltipID1”).set(”rel”, ”This will not change the tooltips text”); $(”tooltipID1”).set(”title”, ”This will not change the tooltips title”); toolTips.detach(”#tooltipID2”); toolTips.detach(”#tooltipID4”); toolTips.attach(”#tooltipID4”); }); </script> </head> <body> <div id = “show” class = “ind”>onShow</div> <div id = “hide” class = “ind”>onHide</div> <p><a id = “tooltipID1” class = “tooltip_demo” title = “1st Tooltip Title” rel = “here is the default ”text” of 1″ href = “http://www.tutorialspoint.com”>Tool tip 1</a></p> <p><a id = “tooltipID2” class = “tooltip_demo” title = “2nd Tooltip Title” rel = “here is the default ”text” of 2″ href = “http://www.tutorialspoint.com”>Tool tip is detached</a></p> <p><a id = “tooltipID3” class = “tooltip_demo_2” title = “3rd Tooltip Title” rel = “here is the default ”text” of 3″ href = “http://www.tutorialspoint.com”>Tool tip 3</a></p> <p><a id = “tooltipID4” class = “tooltip_demo_2” title = “4th Tooltip Title” rel = “here is the default ”text” of 4, i was detached then attached” href = “http://www.tutorialspoint.com”>Tool tip detached then attached again. </a></p> <p><a id = “tooltipID5” class = “tooltip2” title = “Other Tooltip Title” rel = “here is the default ”text” of ”other style”” href = “http://www.tutorialspoint.com/”>A differently styled tool tip</a></p> </body> </html> You will receive the following output − Output Print Page Previous Next Advertisements ”;
MooTools – Classes
MooTools – Classes ”; Previous Next MooTools contains classes of different APIs. Look at the basics of creating and using classes with MooTools. A class is a container for a collection of variables and functions which operate on those variables to perform specific tasks. Let us discuss the variables, methods, and options in detail. Variables Creating a variable is a very simple task. It is like declaring a key/value pairs in hashes. Similarly, you can access the variables in the same manner which means <class_name.variable>. Take a look at the following syntax for creating and accessing variables in classes. Syntax //Create a new class named class_one //with two internal variables var Class_one = new Class({ variable_one : “I”m First”, variable_two : “I”m Second” }); var run_demo_one = function(){ //instantiate a Class_one class called demo_1 var demo_1 = new Class_one(); //Display the variables inside demo_one alert( demo_1.variable_one ); alert( demo_1.variable_two ); } Methods In general, a Method is a function that uses a set of instructions which belongs to a specific class. You can call these functions by using the instance of the class. One more thing whenever you want to call the instance variable into the function you must use this keyword. Take a look at the following syntax for creating and accessing methods. Syntax var Class_two = new Class({ variable_one : “I”m First”, variable_two : “I”m Second”, function_one : function(){ alert(”First Value : ” + this.variable_one); }, function_two : function(){ alert(”Second Value : ” + this.variable_two); } }); var run_demo_2 = function(){ //Instantiate a version of class_two var demo_2 = new Class_two(); //Call function_one demo_2.function_one(); //Call function_two demo_2.function_two(); } initialize initialize is an option in the class object. This helps you create a class setup This also helps you set up user-configuration options and variables. Take a look at the following syntax of initialize option. Syntax var Myclass = new Class({ //Define an initalization function with one parameter initialize : function(user_input){ //create a value variable belonging to //this class and assign it the value //of the user input this.value = user_input; } }) Implementing Options Implementing options are very helpful for accepting user inputs and building classes. Adding the options functionality to your class is as simple as adding another key/pair to the initialization options for your class. Once this setup is ready, you can override any or all of the default options by passing key/value pairs. It provides the setOptions method. This method allows you to set the options once the class has been initialized. If you want to access the variable from inside the class, use the following syntax. Syntax var Class_four = new Class({ Implements: Options, options: { option_one : “Default Value For First Option”, option_two : “Default Value For Second Option”, }, initialize: function(options){ this.setOptions(options); }, show_options : function(){ alert(this.options.option_one + “n” + this.options.option_two); }, }); var run_demo_4 = function(){ var demo_4 = new Class_four({ option_one : “New Value” }); demo_4.show_options(); } var run_demo_5 = function(){ var demo_5 = new Class_four(); demo_5.show_options(); demo_5.setOptions({option_two : “New Value”}); demo_5.show_options(); } //Create a new class_four class with //a new option called new_variable var run_demo_6 = function(){ var demo_6 = new Class_four({new_option : “This is a new option”}); demo_6.show_options(); } Print Page Previous Next Advertisements ”;