This is the HTML part of our demo:
1 2 3 4 5 6 7 8 9 10 11 12 |
<h3 class="title">My personal blog!</h3> <div class="zone"> Visit <a href="http://www.nabilsadki.com" target="_blank">my blog</a> and find lot of usefull tips and tricks about Joomla!, Drupal, Mootools, JQuery and all web stuff! </div> <h3 class="title">Best places in Morocco</h3> <div class="zone"> If you are interested about visiting Morocco, take a look at <a href="http://www.coins.ma" target="_blank">Coins.ma</a>, A nice website where you can find all the best places that you can visit in Morocco! </div> <h3 class="title">KeniClan Family</h3> <div class="zone"> Wanna listen to a Moroccan rap guru's? So check this out! Visit <a href="http://www.keniprod.com" target="_blank">the official website</a> of the KeniClan Family and viber your woofer with Twifly, Sintao, Masty and K-nibal's voices! </div> |
The CSS part:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
h3{ width: 365px; height: 30px; background: url(../images/next.png) 5px 3px no-repeat #666; margin: 0 0 5px 0; padding: 5px 5px 5px 40px; cursor: pointer; color: #fff; border-radius: 5px; text-align: left; } h3.active{ background: url(../images/down.png) 5px 3px no-repeat #666; } .zone{ margin: 5px 0 5px 0; padding: 5px; border: 1px solid #ccc; width: 398px; border-radius: 5px; } |
And finaly the most important step, the JS part :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
// Implement isHidden/isVisible methods into Element class Element.implement({ //Method to check if an element is hidden isHidden: function(){ var w = this.offsetWidth, h = this.offsetHeight, force = (this.tagName === 'TR'); return (w===0 && h===0 && !force) ? true : (w!==0 && h!==0 && !force) ? false : this.getStyle('display') === 'none'; }, // Method to check if an element is visible isVisible: function(){ return !this.isHidden(); } }); window.addEvent('domready', function() { //Close all content blocks $('.zone').setStyle('display', 'none'); //Add class 'active to the first tab, and show his content $('.accordion').getFirst('.title').addClass('active').getNext().setStyle('display', 'block'); //Init the title click $('.title').addEvent('click', function(e){ // Check if the content of the clicked title is hidden, if yes : if ( $(this).getNext().isHidden() ) { //Close content of the active title and remove the active class $('.title').removeClass('active').getNext().setStyle('display', 'none'); //Add class 'active to the clicked title, and show his content $(this).toggleClass('active').getNext().setStyle('display', 'block'); } }); }); |
More infos : This script is based on version 1.2 of Mootools, there is not much difference with version 1.1 of Mootools for this script.
’)
View demo page