JavaScript - Reverse / Drop Up Style Accordion
Howdy Community,
I have spent the past 4 hours strait looking for and trying to modify an accordion style vertical menu who's elements slide out of the top and up instead of the normal slide out of the bottom and down action. I would like it in jQuery, but at this point I will take any library. Thanks for your help. I know some have wondered "What have you tried making work".. jQuery Tools, Jquery UI and about 3 other scripts that looked updateable. All I couldn't get to work. I also made an attempt to fake an accordion using show/hide toggles and this sorta worked, but it didnt have the nice slide as well as my data didnt move on page in the right direction. Headache!!! Help!! Thanks, Cesar Similar TutorialsI have been searching for a long time but have been unsuccessful on how to develop a drop down menu but have the menu items show in a list above the main nav. Not below. I really like the way this functions: http://www.sohtanaka.com/web-design/examples/toggle/ But I would like the item in the list to appear above the main nav so it animates up not down. Can anyone help me on how to alter this js code to perform this task? Here is the jQuery file link: http://code.jquery.com/jquery-latest.js I tried going through this js file but it very complex. Can anyone tell me what I need to change to have the animation roll up instead of down? Any help would be most appreciated. Hey everyone. I'm looking for a tutorial or open source script to accomplish the following tasks: 1 - Accordion style vertical list that expands element (Film # and description) when "+more" link is clicked, and closes the previous open film and description. 2 - Activation of "+ more" shows a photo in separate div, and hides the previous photo that was visible in this separate div. I've attached a mockup photo of the idea I need to execute. Seems like a simple idea, but I have not been able to find a similar example/tutorial online. If anyone can point me in the right direction, that would be greatly appreciated. Thanks. Hello. I need to make drop down box, with 2 statments: hide, show. And I need one table, that javascript set [style="display: none"](When the dorp dow is: hide) and [style="";](When the DDB is set to: show. Can any one help a little, please? I need help with a javascript calculation. I am a noobie developer as you will probably see by my script but here are my goals: I already have a working bmi calculator for my website where visitor will enter height and current weight to calculate their current bmi. then I want to have a reverse bmi calculator to grab the same height and weight from said bmi calculator to give a calculation with a fillable goal bmi (example: 18-24 "healthy bmi") to read out a goal weight for them to achieve. I have already figured out the first part of the bmi calculation now i just need the second calculation to grab the height and weight from original bmi calculator without needing to be filled in again and compute result in a second table. I will post code that I have come up with so far for the whole page. Thank you in advance for your help! [CODE] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title> HCG Drops Fat Lose 1-2 pounds Per Day! </title> <style type="text/css"> #wrapall { width:1000px; align:center; margin-left: 7em; margin-right: 7em; } #navigationbar{ } #bmibar { width:973px; background-image:url(bmibar2.jpg); background-repeat:no-repeat; background-position:left bottom; padding-bottom:16em; margin:4px; } #Hcgborder { width:973px; background-image:url(index_15.jpg); background-repeat:no-repeat; background-position:left bottom; padding-bottom:17em; } #Hcgborder h3 { width:973px; background-image:url(index_12.jpg); background-repeat:no-repeat; background-position:left top; margin:0px; padding-left:4em; padding-top:8em; } p { background-image:url(index_13.jpg); background-repeat:repeat-y; background-position:left center; margin:0px; padding-left:4em; padding-right:4em; font:family"arial" } #bmiscale{ font-size:14px; padding-left:15px; } #Hcgborder2 { width:973px; background-image:url(index_19.jpg); background-repeat:no-repeat; background-position:left bottom; padding-bottom:0.5em; } #dhtmlgoodies_bmi_calculator{ width:180px; /* Width of entire calculator */ height:145px; /* Height of entire calculator */ font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif; /* Fonts to use */ } #dhtmlgoodies_bmi_calculator .calculator_form{ /* Form */ width:180px; /* Width of form div */ float:left; /* Position the form at the left of the graph */ padding-left:5px; padding-right:5px; } #dhtmlgoodies_bmi_calculator input{ width:130px; } #dhtmlgoodies_bmi_calculator .calculator_form .textInput{ width:40px; /* Width of small text inputs */ text-align:right; /* Right align input text */ } .barContainer{ /* DIV for both the multicolor bar and users weight bar */ position:absolute; bottom:0px; border:0px solid #4ff; border-bottom:0px; text-align:center; vertical-align:middle; } .barContainer div{ /* colored div inside "barContainer */ border-bottom:1px solid #000; } .barContainer .labelSpan{ /* Label indicating users BMI */ background-color:#FFF; /* White BG */ border:1px solid #000; /* Black border */ padding:1px; /* "Air" inside the box */ font-size:0.9em; /* Font size */ } .clear{ /* Clearing div - you shouldn't do anything with this one */ clear:both; } </style> <script type="text/javascript"> var useCm = false; // Using centimetre for height, false = inch var useKg = false // Using kilos for weight, false = pounds var graphColors = ['#00baff','#02eb07','#ffb400','#ff0000']; var graphLabels = ['']; var labelsPerRow = 1; /* Help labels above graph */ var barHeight = 50; // Total height of bar var barWidth = 50; // Width of bars */ // Don't change anything below this point */ var calculatorObj; var calculatorGraphObj; var bmiArray = [0,18.5,25,30,60]; /* BMI VALUES */ var weightDiv = false; function calculateBMI() { var height = document.bmi_calculator.bmi_height.value; var weight = document.bmi_calculator.bmi_weight.value; height = height.replace(',','.'); weight = weight.replace(',','.'); if(!useKg)weight = weight / 2.2; if(!useCm)height = height * 2.54; if(isNaN(height))return; if(isNaN(weight))return; height = height / 100; var bmi = weight / (height*height); createWeightBar(bmi); } function createWeightBar(inputValue){ if(!weightDiv){ self.status = Math.random(); weightDiv = document.createElement('DIV'); weightDiv.style.width = barWidth + 'px'; weightDiv.className='barContainer'; weightDiv.style.left = Math.round((calculatorGraphObj.offsetWidth/2) + ((calculatorGraphObj.offsetWidth/2) /2) - (barWidth/2)) + 'px'; calculatorGraphObj.appendChild(weightDiv); var span = document.createElement('SPAN'); weightDiv.appendChild(span); var innerSpan = document.createElement('SPAN'); innerSpan.className='labelSpan'; span.appendChild(innerSpan); }else{ span = weightDiv.getElementsByTagName('SPAN')[0]; innerSpan = weightDiv.getElementsByTagName('SPAN')[1]; } var color = graphColors[graphColors.length-1]; for(var no = bmiArray.length-1;no>0;no--){ if(bmiArray[no]>inputValue)weightDiv.style.backgroundColor = graphColors[no-1]; } if(inputValue/1>1){ innerSpan.innerHTML = inputValue.toFixed(2); span.style.display='inline'; }else span.style.display='none'; var height = Math.min(Math.round(barHeight * (inputValue / bmiArray[bmiArray.length-1])),barHeight-10); span.style.lineHeight = Math.round(height) + 'px'; weightDiv.style.height = height + 'px'; } function validateField() { this.value = this.value.replace(/[^0-9,\.]/g,''); } function initBmiCalculator() { calculatorObj = document.getElementById('dhtmlgoodies_bmi_calculator'); calculatorGraphObj = document.getElementById('bmi_calculator_graph'); if(!useCm)document.getElementById('bmi_label_height').innerHTML = 'inches'; if(!useKg)document.getElementById('bmi_label_weight').innerHTML = 'pounds'; var heightInput = document.getElementById('bmi_height'); heightInput.onblur = validateField; var widthInput = document.getElementById('bmi_height'); widthInput.onblur = validateField; var labelDiv = document.createElement('DIV'); labelDiv.className = 'graphLabels'; calculatorGraphObj.appendChild(labelDiv); for(var no=graphLabels.length-1;no>=0;no--){ var colorDiv = document.createElement('DIV'); colorDiv.className='square'; colorDiv.style.backgroundColor = graphColors[no]; colorDiv.innerHTML = '<span></span>'; labelDiv.appendChild(colorDiv); var labelDivTxt = document.createElement('DIV'); labelDivTxt.innerHTML = graphLabels[no]; labelDiv.appendChild(labelDivTxt); labelDivTxt.className='label'; if((no+1)%labelsPerRow==0){ var clearDiv = document.createElement('DIV'); clearDiv.className='clear'; labelDiv.appendChild(clearDiv); } } var clearDiv = document.createElement('DIV'); clearDiv.className='clear'; labelDiv.appendChild(clearDiv); var graphDiv = document.createElement('DIV'); graphDiv.className='barContainer'; graphDiv.style.width = barWidth + 'px'; graphDiv.style.left = Math.round(((calculatorGraphObj.offsetWidth/2) /2) - (barWidth/2)) + 'px'; graphDiv.style.height = barHeight; calculatorGraphObj.appendChild(graphDiv); var totalHeight = 0; for(var no=bmiArray.length-1;no>0;no--){ var aDiv = document.createElement('DIV'); aDiv.style.backgroundColor = graphColors[no-1]; aDiv.innerHTML = '<span></span>'; var height = Math.round(barHeight * (bmiArray[no] - bmiArray[no-1]) / bmiArray[bmiArray.length-1]) - 1; aDiv.style.height = height + 'px'; graphDiv.appendChild(aDiv); } createWeightBar(1); } </script> <!-- function cal_bmi(lbs, ins){ h2 = ins * ins; bmi = lbs * h2/703 wtl = h2/703 * 24.9 f_bmi = Math.floor(bmi); diff = bmi - f_bmi; diff = diff * 10; diff = Math.round(diff); if (diff == 10){ f_bmi += 1; diff = 0; } bmi = f_bmi + "." + diff; return bmi; } function compute(){ var f = self.document.forms[0]; w = f.wt.value; v = f.htf.value; u = f.hti.value; // Format values for the calculation if (!chkw(u)){ var ii = 0; f.hti.value = 0; } else { var ii = parseInt(f.hti.value); } var fi = parseInt(f.htf.value * 12); var i = fi + ii; // Do validation of remaining fields if (!chkw(v)){ alert("Please enter your height."); f.htf.focus(); return; } if (!chkw(w)){ alert("Please enter your weight."); f.wt.focus(); return; } // Perform calculation f.bmi.value = cal_bmi(w, i); f.bmi.focus(); } function chkw(w){ if (isNaN(parseInt(w))){ return false; } else if (w < 0){ return false; } else{ return true; } } // --> </style> </head> <body> <div id="wrapall" align="center"> <img src="index_01_01.jpg" alt="Hcg drops fat banner"> <br/> <div id="navigationbar"> <a href="http://www.hcgdropsfat.com"><img src=hcghomeog.jpg border=0></a> <img src="hcgblogo.jpg" alt="Hcg blog"/> <img src="hcgfaqo.jpg" alt="Hcg faq"> <img src="hcgresourceso.jpg" alt="Hcg resources"> <img src="hcgtestimonialso.jpg" alt="Hcg testimonials"> <img src="hcgsupporto.jpg" alt="Hcg support"> <img src="hcgordero.jpg" alt="Hcg order"> <div id="bmibar"> <div style="position: absolute; top: 515px; left: 170px"; style="font-family: arial"; align="left";> How much is your weight in <br/>relation to your height <br/> <!--BMI CALCULATOR SCRIPT--> <div id="dhtmlgoodies_bmi_calculator"> <div class="calculator_form"> <form name="bmi_calculator"> <table> <tr> <td><label for="bmi_height">Height</label>:</td><td><input class="textInput" type="text" id="bmi_height" name="bmi_height"> <span id="bmi_label_height">cm</span></td> </tr> <tr> <td><label for="bmi_weight">Weight</label>:</td><td><input class="textInput" type="text" id="bmi_weight" name="bmi_weight"> <span id="bmi_label_weight">kg</span></td> </tr> <tr> <td colspan="2"><input type="button" onclick="calculateBMI()" value="Find BMI"></td> </tr> </table> </form> </div> <div class="calculator_graph" id="bmi_calculator_graph"> </div> </div> <script type="text/javascript"> initBmiCalculator(); </script> </div> <div style="position: absolute; top: 515px; left: 405px"; style="font-family: arial"; align="left";> What is your BMI category? <br/>This will help determine <br/>how much you need to lose <br/><br/><div id="bmiscale">Underweight = Under 18.5 <br/>Normal weight = 18.5 – 24.9 <br/>Overweight = 25 – 29.9 <br/>Obesity = 30 or more <br/><br/> </div></div> <div style="position: absolute; top: 515px; left: 640px"; style="font-family: arial"; align="left";> Calculate approximately how <br/>much weight you should lose<br/> to be at a healthy BMI <!--REVERSE BMI CALCULATOR--> <td width="81%" valign="top"> <br/><div align="center" class="page_header">Reverse BMI Calculator</div><br/> <div align="center" class="main_text"></div> <form action="" method="post" name="BMI_input" class="main_text" id="BMI_input"> <div style="text-align: center;"><font face="Arial, Helvetica, sans-serif">Target BMI:<b> <input id="FormsEditField4" type="text" name="wt" value="24" size="3" maxlength="2" /> <br /> </b></font></div> <div style="text-align: center;"> <font face="Arial, Helvetica, sans-serif"> <input type="button" name="FormsButton1" value="Find Target Weight" id="FormsButton1" onclick="self.compute()" /> </font></div> <div style="text-align: center;"><font face="Arial, Helvetica, sans-serif">This is your Target Weight: <br /> <input id="FormsEditField5" type="text" name="bmi" value="" size="4" maxlength="5" /> </font></div> </div> </div> <div id="Hcgborder"> <h3></h3> <p align="left"><b> WHAT IS HCG? </b><BR/><BR/>In simple terms: its a hormone protein produced by pregnant women that when used as a homeopathic dietary supplement, will assist in a revolutionary cure to the traditional diet routine. <BR/><BR/><b>HCG is so unique from other diets in 3 major ways: </b> <br/><BR/><img src="muscletissue.jpg" alt="practice"style="float:right;" width="250px" height="250px"/> 1. USES HIGHEST FAT AS PRIMARY FUEL SOURCE FOR THE BODY - it begins to break down the abnormally high body fat as the primary fuel source (BURNS ALOT OF FAT!) <BR/>2. DOESNT EAT AT VITAL MUSCLE TISSUE - it will preserve and maintain lean body muscle (without HCG THE BODY WOULD DEPLETE VITAL MUSCLE TISSUE ON A LOW CALORIE DIET. Also if you burn muscle you also lose metabolism for each pound of muscle you lose you also lose 50 calories of metabolism) <BR/>3. WHILE MOST DIETS SLOW METABOLISM HCG ACTUALLY MAINTAINS IT EVEN AFTER THE DIET - because hcg maintains lean muscle and maintains metabolism, you keep your metabolism in check long after the diet program so you reset your bodys roaming weight. <BR/><BR/>THE HOMEOPATHIC DROPS YOU WILL FIND ON OUR SITE ARE ALL NATURAL <br/><BR/><b>HOW LONG HAS IT BEEN AROUND?</b> <BR/><BR/>HCG or (Human chorionic gonadotropin)<img src="nicefigure.jpg" alt="Hcg stored fat" style="float:right;" width="250px" height="250px"/> is a protein hormone </div><!--p1--> </div><!--Hcgborder--> <div id="Hcgborder2"> <p><b>hello</b></p> <p>Hello again</p> </div><!--Hcgborder2--> </div> </div><!--wrapall--> </body> </html> [CODE] Hi Fellows, Just a quick question, is there a fucntion or a way to get the current date and time of a unix datetime stamp in javascript? I use something like Code: var end_time = end_dateTime.getTime(); but now I need a way to find out what the current date and time is after modifying the end_time variable. Thanks a lot!!! I'm pretty beginner at javascript, and I have this script for letter to phonetic: Code: <script language="JavaScript"> function flip() { var result = flipString(document.f.original.value.toLowerCase()); document.f.flipped.value = result; } function flipString(aString) { var last = aString.length - 1; var result = new Array(aString.length) for (var i = last; i >= 0; --i) { var c = aString.charAt(i) var r = flipTable[c] result[i] = r != undefined ? r : c } return result.join('') } var flipTable = { a : 'aye ', b : 'bee ', c : 'sea ', d : 'dee ', e : 'eeh ', f : 'eff ', g : 'gee ', h : 'aych ', i : 'eye ', j : 'jay ', k : 'kay ', l : 'el ', m : 'em ', n : 'en ', o : 'oh ', p : 'pee ', q : 'cue ', r : 'are ', s : 'es ', t : 'tee ', u : 'you ', v : 'vee ', w : 'doubleyou ', x : 'ex ', y : 'why ', z : 'zee ', 1 : 'one ', 2 : 'two ', 3 : 'three ', 4 : 'four ', 5 : 'five ', 6 : 'six ', 7 : 'seven ', 8 : 'eight ', 9 : 'nine ', 0 : 'zero ', '<' : 'left-inequality ', '>' : 'right-inequality', ':' : 'colon ', ';' : 'semicolon ', '(' : 'left-parenthesis ', ')' : 'right-parenthesis ', ' ' : 'space ', '?' : '? ', '!' : '! ', '.' : '. ', ',' : ', ' } for (i in flipTable) { flipTable[flipTable[i]] = i } </script> It's code based on text flipper. Anyways, if you type in A, the output would be aye. How would I go about switching this script so when one puts in 'aye' the output is the letter A? i just read the other thread and i want the reverse affect. the slideshow opens in a new window and thats not what we want because the link is to a persons profile page. we dont want two versions of the site open at once. this is the slideshow that client did on his own then i got the project. http://www.dynamicdrive.com/dynamici...nslideshow.htm Code: imagearray: [ ["pool.jpg"], ["http://mysite.com/cave.jpg", "http://cnn.com"], ["fruits.jpg", "http://cnn.com", "_new"], ["dog.jpg", "", "", "This image has a description but no hyperlink"] //<--no trailing comma after very last image element! ], i see "_new"], in there but i dont know if there is a command for self is it _self .. im not sure.. i assume it is different than the html target code. so how do i make it open in the same window just like target = self sorry had to change the target to non coded format to show up right in this thread Hi All, I want an accordion menu and which is as follows 1.it should be a vertical accordion menu 2.every menu should display with image and link 3.if i click on image or link then only menu should display or open to show sub menu otherwise it should not display. Please tell the solution for the above ThanksAhead Venkat Hi All, So i have been trying over the past few weeks (among other things) to get this menu figured out. I would really appreciate some advice/help/direction with this... Please see attached pic... what i have is three elements: "Home" "Services" "Contact". What i want is on page load they are all 100px wide... now whenever user hovers over an item it expands to be 200px wide while the other two shrink to 50px... remove hover they revert to original... I am not too familiar with javascript as i mainly use C# to do the tasks normally done by javascript (i work on asp.net platform)... i have presented a similar question to this in ajax section (thinkin that what i had was an ajax work around) but upon further reading of sources i think that is not really what i want... I am unsure where to begin and what to do... i know i need to set up a function and i have the math part figured out (i think)... i guess what i am really unclear as to whether this is a modification to the accordion menu frame... the issues i see are that i do not want the menu to have a traditional "content" area that collapses; i want the menu "headers" to expand... i also need them to expand horizontally not vertically... i am not looking for someone to "do this" for me; i am looking for advice and guidance... possibly a link to a tutorial? i have tried this but it does not work right... i can revisit it (possibly type-Oed something) but i havent because it is not really what i am looking for I'm creating a Jquery UI accordion and here are my customize options... http://jqueryui.com/demos/accordion/ These options do not include how to make all the accordions start off closed or choosing which one you want open as default when a user sees the page. Right now the user sees the first accordion open. I want to keep them all closed by default or have the option to have the last one open by default. Any guidance would be great... also not sure what code to post here but I guess I'll add the javaScript used to create the accordion with Jquery.... Code: /* * jQuery UI Accordion 1.8.16 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. * http://jquery.org/license * * http://docs.jquery.com/UI/Accordion * * Depends: * jquery.ui.core.js * jquery.ui.widget.js */ (function( $, undefined ) { $.widget( "ui.accordion", { options: { active: 0, animated: "slide", autoHeight: true, clearStyle: false, collapsible: false, event: "click", fillSpace: false, header: "> li > :first-child,> :not(li):even", icons: { header: "ui-icon-triangle-1-e", headerSelected: "ui-icon-triangle-1-s" }, navigation: false, navigationFilter: function() { return this.href.toLowerCase() === location.href.toLowerCase(); } }, _create: function() { var self = this, options = self.options; self.running = 0; self.element .addClass( "ui-accordion ui-widget ui-helper-reset" ) // in lack of child-selectors in CSS // we need to mark top-LIs in a UL-accordion for some IE-fix .children( "li" ) .addClass( "ui-accordion-li-fix" ); self.headers = self.element.find( options.header ) .addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" ) .bind( "mouseenter.accordion", function() { if ( options.disabled ) { return; } $( this ).addClass( "ui-state-hover" ); }) .bind( "mouseleave.accordion", function() { if ( options.disabled ) { return; } $( this ).removeClass( "ui-state-hover" ); }) .bind( "focus.accordion", function() { if ( options.disabled ) { return; } $( this ).addClass( "ui-state-focus" ); }) .bind( "blur.accordion", function() { if ( options.disabled ) { return; } $( this ).removeClass( "ui-state-focus" ); }); self.headers.next() .addClass( "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" ); if ( options.navigation ) { var current = self.element.find( "a" ).filter( options.navigationFilter ).eq( 0 ); if ( current.length ) { var header = current.closest( ".ui-accordion-header" ); if ( header.length ) { // anchor within header self.active = header; } else { // anchor within content self.active = current.closest( ".ui-accordion-content" ).prev(); } } } self.active = self._findActive( self.active || options.active ) .addClass( "ui-state-default ui-state-active" ) .toggleClass( "ui-corner-all" ) .toggleClass( "ui-corner-top" ); self.active.next().addClass( "ui-accordion-content-active" ); self._createIcons(); self.resize(); // ARIA self.element.attr( "role", "tablist" ); self.headers .attr( "role", "tab" ) .bind( "keydown.accordion", function( event ) { return self._keydown( event ); }) .next() .attr( "role", "tabpanel" ); self.headers .not( self.active || "" ) .attr({ "aria-expanded": "false", "aria-selected": "false", tabIndex: -1 }) .next() .hide(); // make sure at least one header is in the tab order if ( !self.active.length ) { self.headers.eq( 0 ).attr( "tabIndex", 0 ); } else { self.active .attr({ "aria-expanded": "true", "aria-selected": "true", tabIndex: 0 }); } // only need links in tab order for Safari if ( !$.browser.safari ) { self.headers.find( "a" ).attr( "tabIndex", -1 ); } if ( options.event ) { self.headers.bind( options.event.split(" ").join(".accordion ") + ".accordion", function(event) { self._clickHandler.call( self, event, this ); event.preventDefault(); }); } }, _createIcons: function() { var options = this.options; if ( options.icons ) { $( "<span></span>" ) .addClass( "ui-icon " + options.icons.header ) .prependTo( this.headers ); this.active.children( ".ui-icon" ) .toggleClass(options.icons.header) .toggleClass(options.icons.headerSelected); this.element.addClass( "ui-accordion-icons" ); } }, _destroyIcons: function() { this.headers.children( ".ui-icon" ).remove(); this.element.removeClass( "ui-accordion-icons" ); }, destroy: function() { var options = this.options; this.element .removeClass( "ui-accordion ui-widget ui-helper-reset" ) .removeAttr( "role" ); this.headers .unbind( ".accordion" ) .removeClass( "ui-accordion-header ui-accordion-disabled ui-helper-reset ui-state-default ui-corner-all ui-state-active ui-state-disabled ui-corner-top" ) .removeAttr( "role" ) .removeAttr( "aria-expanded" ) .removeAttr( "aria-selected" ) .removeAttr( "tabIndex" ); this.headers.find( "a" ).removeAttr( "tabIndex" ); this._destroyIcons(); var contents = this.headers.next() .css( "display", "" ) .removeAttr( "role" ) .removeClass( "ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content ui-accordion-content-active ui-accordion-disabled ui-state-disabled" ); if ( options.autoHeight || options.fillHeight ) { contents.css( "height", "" ); } return $.Widget.prototype.destroy.call( this ); }, _setOption: function( key, value ) { $.Widget.prototype._setOption.apply( this, arguments ); if ( key == "active" ) { this.activate( value ); } if ( key == "icons" ) { this._destroyIcons(); if ( value ) { this._createIcons(); } } // #5332 - opacity doesn't cascade to positioned elements in IE // so we need to add the disabled class to the headers and panels if ( key == "disabled" ) { this.headers.add(this.headers.next()) [ value ? "addClass" : "removeClass" ]( "ui-accordion-disabled ui-state-disabled" ); } }, _keydown: function( event ) { if ( this.options.disabled || event.altKey || event.ctrlKey ) { return; } var keyCode = $.ui.keyCode, length = this.headers.length, currentIndex = this.headers.index( event.target ), toFocus = false; switch ( event.keyCode ) { case keyCode.RIGHT: case keyCode.DOWN: toFocus = this.headers[ ( currentIndex + 1 ) % length ]; break; case keyCode.LEFT: case keyCode.UP: toFocus = this.headers[ ( currentIndex - 1 + length ) % length ]; break; case keyCode.SPACE: case keyCode.ENTER: this._clickHandler( { target: event.target }, event.target ); event.preventDefault(); } if ( toFocus ) { $( event.target ).attr( "tabIndex", -1 ); $( toFocus ).attr( "tabIndex", 0 ); toFocus.focus(); return false; } return true; }, resize: function() { var options = this.options, maxHeight; if ( options.fillSpace ) { if ( $.browser.msie ) { var defOverflow = this.element.parent().css( "overflow" ); this.element.parent().css( "overflow", "hidden"); } maxHeight = this.element.parent().height(); if ($.browser.msie) { this.element.parent().css( "overflow", defOverflow ); } this.headers.each(function() { maxHeight -= $( this ).outerHeight( true ); }); this.headers.next() .each(function() { $( this ).height( Math.max( 0, maxHeight - $( this ).innerHeight() + $( this ).height() ) ); }) .css( "overflow", "auto" ); } else if ( options.autoHeight ) { maxHeight = 0; this.headers.next() .each(function() { maxHeight = Math.max( maxHeight, $( this ).height( "" ).height() ); }) .height( maxHeight ); } return this; }, activate: function( index ) { // TODO this gets called on init, changing the option without an explicit call for that this.options.active = index; // call clickHandler with custom event var active = this._findActive( index )[ 0 ]; this._clickHandler( { target: active }, active ); return this; }, _findActive: function( selector ) { return selector ? typeof selector === "number" ? this.headers.filter( ":eq(" + selector + ")" ) : this.headers.not( this.headers.not( selector ) ) : selector === false ? $( [] ) : this.headers.filter( ":eq(0)" ); }, // TODO isn't event.target enough? why the separate target argument? _clickHandler: function( event, target ) { var options = this.options; if ( options.disabled ) { return; } // called only when using activate(false) to close all parts programmatically if ( !event.target ) { if ( !options.collapsible ) { return; } this.active .removeClass( "ui-state-active ui-corner-top" ) .addClass( "ui-state-default ui-corner-all" ) .children( ".ui-icon" ) .removeClass( options.icons.headerSelected ) .addClass( options.icons.header ); this.active.next().addClass( "ui-accordion-content-active" ); var toHide = this.active.next(), data = { options: options, newHeader: $( [] ), oldHeader: options.active, newContent: $( [] ), oldContent: toHide }, toShow = ( this.active = $( [] ) ); this._toggle( toShow, toHide, data ); return; } // get the click target var clicked = $( event.currentTarget || target ), clickedIsActive = clicked[0] === this.active[0]; // TODO the option is changed, is that correct? // TODO if it is correct, shouldn't that happen after determining that the click is valid? options.active = options.collapsible && clickedIsActive ? false : this.headers.index( clicked ); // if animations are still active, or the active header is the target, ignore click if ( this.running || ( !options.collapsible && clickedIsActive ) ) { return; } // find elements to show and hide var active = this.active, toShow = clicked.next(), toHide = this.active.next(), data = { options: options, newHeader: clickedIsActive && options.collapsible ? $([]) : clicked, oldHeader: this.active, newContent: clickedIsActive && options.collapsible ? $([]) : toShow, oldContent: toHide }, down = this.headers.index( this.active[0] ) > this.headers.index( clicked[0] ); // when the call to ._toggle() comes after the class changes // it causes a very odd bug in IE 8 (see #6720) this.active = clickedIsActive ? $([]) : clicked; this._toggle( toShow, toHide, data, clickedIsActive, down ); // switch classes active .removeClass( "ui-state-active ui-corner-top" ) .addClass( "ui-state-default ui-corner-all" ) .children( ".ui-icon" ) .removeClass( options.icons.headerSelected ) .addClass( options.icons.header ); if ( !clickedIsActive ) { clicked .removeClass( "ui-state-default ui-corner-all" ) .addClass( "ui-state-active ui-corner-top" ) .children( ".ui-icon" ) .removeClass( options.icons.header ) .addClass( options.icons.headerSelected ); clicked .next() .addClass( "ui-accordion-content-active" ); } return; }, _toggle: function( toShow, toHide, data, clickedIsActive, down ) { var self = this, options = self.options; self.toShow = toShow; self.toHide = toHide; self.data = data; var complete = function() { if ( !self ) { return; } return self._completed.apply( self, arguments ); }; // trigger changestart event self._trigger( "changestart", null, self.data ); // count elements to animate self.running = toHide.size() === 0 ? toShow.size() : toHide.size(); if ( options.animated ) { var animOptions = {}; if ( options.collapsible && clickedIsActive ) { animOptions = { toShow: $( [] ), toHide: toHide, complete: complete, down: down, autoHeight: options.autoHeight || options.fillSpace }; } else { animOptions = { toShow: toShow, toHide: toHide, complete: complete, down: down, autoHeight: options.autoHeight || options.fillSpace }; } if ( !options.proxied ) { options.proxied = options.animated; } if ( !options.proxiedDuration ) { options.proxiedDuration = options.duration; } options.animated = $.isFunction( options.proxied ) ? options.proxied( animOptions ) : options.proxied; options.duration = $.isFunction( options.proxiedDuration ) ? options.proxiedDuration( animOptions ) : options.proxiedDuration; var animations = $.ui.accordion.animations, duration = options.duration, easing = options.animated; if ( easing && !animations[ easing ] && !$.easing[ easing ] ) { easing = "slide"; } if ( !animations[ easing ] ) { animations[ easing ] = function( options ) { this.slide( options, { easing: easing, duration: duration || 700 }); }; } animations[ easing ]( animOptions ); } else { if ( options.collapsible && clickedIsActive ) { toShow.toggle(); } else { toHide.hide(); toShow.show(); } complete( true ); } // TODO assert that the blur and focus triggers are really necessary, remove otherwise toHide.prev() .attr({ "aria-expanded": "false", "aria-selected": "false", tabIndex: -1 }) .blur(); toShow.prev() .attr({ "aria-expanded": "true", "aria-selected": "true", tabIndex: 0 }) .focus(); }, _completed: function( cancel ) { this.running = cancel ? 0 : --this.running; if ( this.running ) { return; } if ( this.options.clearStyle ) { this.toShow.add( this.toHide ).css({ height: "", overflow: "" }); } // other classes are removed before the animation; this one needs to stay until completed this.toHide.removeClass( "ui-accordion-content-active" ); // Work around for rendering bug in IE (#5421) if ( this.toHide.length ) { this.toHide.parent()[0].className = this.toHide.parent()[0].className; } this._trigger( "change", null, this.data ); } }); $.extend( $.ui.accordion, { version: "1.8.16", animations: { slide: function( options, additions ) { options = $.extend({ easing: "swing", duration: 300 }, options, additions ); if ( !options.toHide.size() ) { options.toShow.animate({ height: "show", paddingTop: "show", paddingBottom: "show" }, options ); return; } if ( !options.toShow.size() ) { options.toHide.animate({ height: "hide", paddingTop: "hide", paddingBottom: "hide" }, options ); return; } var overflow = options.toShow.css( "overflow" ), percentDone = 0, showProps = {}, hideProps = {}, fxAttrs = [ "height", "paddingTop", "paddingBottom" ], originalWidth; // fix width before calculating height of hidden element var s = options.toShow; originalWidth = s[0].style.width; s.width( parseInt( s.parent().width(), 10 ) - parseInt( s.css( "paddingLeft" ), 10 ) - parseInt( s.css( "paddingRight" ), 10 ) - ( parseInt( s.css( "borderLeftWidth" ), 10 ) || 0 ) - ( parseInt( s.css( "borderRightWidth" ), 10) || 0 ) ); $.each( fxAttrs, function( i, prop ) { hideProps[ prop ] = "hide"; var parts = ( "" + $.css( options.toShow[0], prop ) ).match( /^([\d+-.]+)(.*)$/ ); showProps[ prop ] = { value: parts[ 1 ], unit: parts[ 2 ] || "px" }; }); options.toShow.css({ height: 0, overflow: "hidden" }).show(); options.toHide .filter( ":hidden" ) .each( options.complete ) .end() .filter( ":visible" ) .animate( hideProps, { step: function( now, settings ) { // only calculate the percent when animating height // IE gets very inconsistent results when animating elements // with small values, which is common for padding if ( settings.prop == "height" ) { percentDone = ( settings.end - settings.start === 0 ) ? 0 : ( settings.now - settings.start ) / ( settings.end - settings.start ); } options.toShow[ 0 ].style[ settings.prop ] = ( percentDone * showProps[ settings.prop ].value ) + showProps[ settings.prop ].unit; }, duration: options.duration, easing: options.easing, complete: function() { if ( !options.autoHeight ) { options.toShow.css( "height", "" ); } options.toShow.css({ width: originalWidth, overflow: overflow }); options.complete(); } }); }, bounceslide: function( options ) { this.slide( options, { easing: options.down ? "easeOutBounce" : "swing", duration: options.down ? 1000 : 200 }); } } }); })( jQuery ); Hello to all, I have a little problem with my accordion menu and I CRAVE for your help! I try to make this: when you visit my page I need the menu to be all collapsed. Also the history of clicks (it remembers which menus where left opened) works fine on IE but not on firefox. Here is the js code: function add_menu_event_handlers() { var elems = document.getElementsByTagName('h3'); for (i = 0; i < elems.length; i++) { switch (elems[i].parentNode.className) { /*case 'moduletable': case 'moduletable_menu':*/ case 'left_module_title': case 'left_module_title_menu': { if (elems[i].parentNode.parentNode.parentNode.id == 'xp-left') { xplike_addEvent(elems[i], 'click', function(){menu_header_click(this);}); // menu_header_click(elems[i]); //Load status from cookies and collapse if required var cookie_array = document.cookie.split(';'); for(var j=0; j<cookie_array.length; j++) { var c = cookie_array[j]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf('xplike_menu_status_' + elems[i].firstChild.nodeValue.replace('.', '_').replace(' ', '_')) == 0) { var menu_cookie = c.split('=') if (menu_cookie.length == 2 && menu_cookie[1] == '1') { menu_header_click(elems[i]); } } } } } } } } And it also has this for the history thing. function save_menu_status(menu_title, value, how_many_days) { var date = new Date(); date.setTime(date.getTime()+(how_many_days*24*60*6 0*1000)); var expires = ""; document.cookie = 'xplike_menu_status_' + menu_title.replace('.', '_').replace(' ', '_') + '=' + value + expires + '; path=/'; } It might be easy and stupid, I know, but since I'm a designer - not a developer - all look weird to me! Any thoughts? Hi All, Does anyone know of any good horizontal accordion scripts that use jquery, like this one: http://www.slidedeck.com/ I would like something very similar to that but unfortunately the free version is as customizable as I need it to be. I've done a Google search but found nothing as of yet... Thanks, Greens85 Hey everyone. If you go he
Code: http://store.inspirationsdancewear.com/?xls_offlinekey=4888254 you will see an "accordion" navigation on the left side. It opens and contracts like it should, HOWEVER I need to add the following functionality. 1. I want to have ONLY 1 "parent" category displaying it's "child" categories at a time. So when I open another "parent" link, I want the previous one to collapse, so only 1 accordion is open at a time (right now you are able to open all of them without the other ones collapsing). 2. When I select a "child" category from the "parent" category, I need the menu to stay open when going to the "child" category page and I also need the relevant "child" category to be "highlighted" so the user knows which page they are on. Please let me know if you can help me with any of this. I would GREATLY appreciate it!! PHP Code: <script type="text/javascript"> //----------------------------NAVIGATION DROPDOWN------------------------------------// sfHover = function() { var sfEls = document.getElementById("left").getElementsByTagName("h2"); for (var i=0; i<sfEls.length; i++) { sfEls[i].onmouseover=function() { this.className+=" sfhover"; } sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); } } } if (window.attachEvent) window.attachEvent("onload", sfHover); function initMenu() { $('#left div').hide(); $('#left h2').click( function() { $(this).next().slideToggle('normal'); } ); } $(document).ready(function() {initMenu();}); </script> <?php function print_childs($categ){ $childs = $categ->categ_childs; if(!$childs || (count($childs) == 0)){ echo "</a>"; return; } echo "»</a><ul>\n"; foreach($childs as $category){ if(!$category->HasChildOrProduct()) continue; ?> <li><a class="childcats" href="<?= $category->Link; ?>"><?= $category->Name; ?><?php print_childs($category); ?></a></li> <?php } echo "</ul><br/>\n"; } ?> <div id="leftwrapper"> <h2 style="margin-top:-25px; padding-bottom:15px; color:#900; margin-left:15px; font-size:1.2em">Shop Online</h2> <div id="left"> <?php foreach($this->menu_categories as $category): ?> <h2 class="headings"> <?= $category->Name; ?></h2> <div> <a class="childcats" href="<?= $category->Link; ?>"> See all <?= $category->Name; ?> <?php print_childs($category); ?></a> </div> <?php endforeach; ?> <?php if(_xls_get_conf('ENABLE_FAMILIES', 1)): ?> <?php $families = Family::LoadAll();?> <?php foreach($families as $family): ?> <a href="index.php?family=<?= $family->Family ?>"><?= $family->Family ?></a> <?php endforeach; ?> <?php endif; ?> </div> </div> I’m trying to implement a JavaScript that creates an accordion menu. As the script currently stands, your able to tell the first list within the menu to expand when the page loads. You do this by adding .expandfirst into the ul class tag. My question is... Does anyone know how to edit the JavaScript so that I can also tell the menu (on some pages) to expand the second or third list? I only need one list to be expanded at any one time. Here's the script... Code: function initMenus() { $('ul.menu ul').hide(); $.each($('ul.menu'), function(){ $('#' + this.id + '.expandfirst ul:first).show(); }); $('ul.menu li a').click( function() { var checkElement = $(this).next(); var parent = this.parentNode.parentNode.id; if($('#' + parent).hasClass('noaccordion')) { $(this).next().slideToggle('normal'); return false; } if((checkElement.is('ul')) && (checkElement.is(':visible'))) { if($('#' + parent).hasClass('collapsible')) { $('#' + parent + ' ul:visible').slideUp('normal'); } return false; } if((checkElement.is('ul')) && (!checkElement.is(':visible'))) { $('#' + parent + ' ul:visible').slideUp('normal'); checkElement.slideDown('normal'); return false; } } ); } $(document).ready(function() {initMenus();}); Hope someone can help!? I am working on a custom accordion. A type 2 accordion works but type 1 and 3 don't work. Does anyone know how to correct this syntax? Also, if you see any ways to make this code better, please post your fixes in this post Code: /* To use these, insert your content between a div tag. For example: <div id="2011" style="display: none"> This is the content in the accordion </div> You can have as many of these on the page as you wish but they all must have a different div tag. You will be creating a different button for each div tag. To make an item display on page load, change that div tag display from "none" to "inline". For the button that toggles the accordion: <a href="javascript:accordion('2011', '2', eventyear)">2011</a> Here is what all of these variables do: 1. Id of the div tag you want to toggle 2. The type of accordion you want 3. Only needed if it is a type 1 or 2 accordion, this refers to an array of all of the other div id's in the accordion. If you are using a type 1 or 2 array, create a array under the arrays comment of all of the div id's in your accordion. Types: 1 = One open at a time. Open and close 2 = One open at a time. Open no close 3 = No limit. Open and close. 3 doesn't use an array */ //Arrays; var eventyear=new Array("2011","2010","2009"); var months=new Array("January","February","March","April","May","June","July","August","September","October","November","December"); function accordion(click,type,array) { var click = document.getElementById(click); if ((click.style.display = "inline") && ((type == "1") || (type == "3"))) { click.style.display = "none"; } else if ((click.style.display = "none") && ((type == "1") || (type == "2"))) { var c; for(c in array) { document.getElementById(array[c]).style.display = "none"; } click.style.display = "inline"; } else if ((click.style.display = "none") && (type == "3")) { click.style.display = "inline"; }} Hello people, I got a problem. This is the code for hiding en showing informatie in an acordion. It looks fine and it works! But it only handles one div! The main thing i want is that when i click on the text "button" the next div, with all the span's within it, has to slide under. Example: HTML: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Accordion 1</title> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".accordion h3:first").addClass("active"); $(".accordion div:not(:first)").hide(); $(".accordion div").hide(); $(".accordion p").hide(); $(".accordion h3").click(function(){ $(this).next("div").slideToggle("slow").siblings("div:visible").slideUp("slow"); $(this).toggleClass("active"); $(this).siblings("h3").removeClass("active"); $(".accordion p").show(); $(".accordion .button").show(); }); }); </script> <link rel="stylesheet" href="css/style.css" type="text/css"/> </head> <body> <div class="accordion"> <h3>Title</h3> <div class="test"> <p>subtext</p> <div class="button"> <a href="" title="">Button</a> </div> </div> <div> <span style="display:block; height: 20px; width: 220px; margin-top: 10px; margin-left: -5px;"><input type="radio" checked="checked" value="" name="" id="" /><label for="">test</label></span> <span style="display:block; height: 20px; width: 220px; margin-top: 0px; margin-left: -5px; margin-bottom: 20px;"><input type="radio" value="" name="" id="" /><label for="">test</label></span> <span style="font-weight:bold;">Vanaf<input type="text" style="width: 20px; height: 15px;" class="" value="1" readonly=""></input>-<input type="text" style="width: 20px; height: 15px;" class="" value="" readonly=""></input>-<input type="text" style="width: 40px; height: 15px;" class="" value="1" readonly=""></input> change to <input type="text" style="width: 20px; height: 10px;" class="" value="" readonly=""></input>%</span> <span style="display:block; text-align: right; text-decoration:underline; font-weight:bold; color: red;">count</span> </div> </div> </body> </html> CSS: Code: body { margin: 10px auto; width: 570px; font: 75%/120% Arial, Helvetica, sans-serif; } .accordion { width: 480px; border-bottom: solid 1px #c4c4c4; } .accordion h3 { background: #004584; padding: 7px 15px; margin: 0; font: bold 120%/100% Arial, Helvetica, sans-serif; border: solid 1px #c4c4c4; border-bottom: none; cursor: pointer; color: #FFFFFF; } .accordion h3:hover { background-color: #00AEE7; } .accordion h3.active { background-position: right 5px; } .accordion .test { background: #DFF7FF; margin: 0; padding: 10px 15px 20px; border-left: solid 1px #c4c4c4; border-right: solid 1px #c4c4c4; } .accordion .extra { background: #DFF7FF; margin: 0; padding: 10px 15px 20px; border-left: solid 1px #c4c4c4; border-right: solid 1px #c4c4c4; } I have this accordion : accordion example I want to separate each item into 3 columns. I tried using table but it doesn't work (it made the text not clickable). Any idea how? Thank you Hi, I mainly do PHP/MySQL coding, but I wanted to add this Javascript Accordion Menu to my site: Javascript And CSS Tutorial - Accordion Menus | Switch on the Code It works fine, but I was wondering if there was a simple way to modify the code so that the currently open menu stays open from page to page instead of closing upon each page reload? Thanks for the help, --Anamaniac I'm making an JS accordion and I just miss the final step. That is - say: I click menu 1, content 1 slides down (shows up). After that, I click menu 2, content 2 slides down but content 1 of menu 1 just display: none (abruptly disappers) but not slides up. For the slide up effect, I wrote a function called cutHeight(). The cutHeight function works perfectly independently but not coherent with the accordion function. Is there anything wrong with my scripts? Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script> function accordion(openAccordionID){ document.getElementById("content"+openAccordionID).style.display = (document.getElementById("content"+openAccordionID).style.display == "none") ? "block" : "none" ; var sumAccordion; if(document.all){ sumAccordion = document.body.getElementsByTagName("div").length/2; } else {sumAccordion = document.getElementsByClassName("content").length;} for(var closeAccordionID=1; closeAccordionID<=sumAccordion; closeAccordionID++){ if(closeAccordionID == openAccordionID){continue;} document.getElementById("content"+closeAccordionID).style.display = "none"; } addHeight(openAccordionID); cutHeight(closeAccordionID); } var h=0; var t; function addHeight(openAccordionID){ clearInterval(t); document.getElementById("content"+openAccordionID).style.height = h+"px"; h+=1; t = setInterval("addHeight('"+openAccordionID+"')",10); if(h==100){clearInterval(t);h=0;} } var T; function cutHeight(closeAccordionID){ var h=100; clearInterval(T); document.getElementById("content"+closeAccordionID).style.height = h+"px"; h-=1; T = setInterval("cutHeight('"+closeAccordionID+"')",10); if(h==0){clearInterval(T);} } </script> <style> .menu { background-color: #6F6; width: 200px; height: 50px;} .content { display: none; background-color: yellow; width: 200px; height:0px; overflow: hidden;} </style> </head> <body> <div onclick="accordion(1)" class="menu">Menu 1</div> <div id="content1" class="content">Content 1</div> <div onclick="accordion(2)" class="menu">Menu 2</div> <div id="content2" class="content">Content 2</div> <div onclick="accordion(3)" class="menu">Menu 3</div> <div id="content3" class="content">Content 3</div> </body> </html> |