I need one menu with horizontal accordion, but the plugins that I have looked doesn't like me, too much requirements or code, really I need something more simple, so in few minutes I write a simple plugin.
v0.1
It is very simple, with a few parameters: speed set the velocity of the animation, headerclass set another classname for header divs (by default "header"), contentclass set another classname for content divs (by default "content"), contentwidth is the final with of each content panel.
HTHML Sample:
.haccordion .header, .haccordion .content{
float: left;
height: 250px;
}
.haccordion .header{
width: 20px;
background: #ccc;
color: #fff;
cursor: pointer;
}
.haccordion .content{
display: none;
width: 0px;
overflow: auto;
}
.haccordion .content p{
margin: 5px;
}
*1
This is a sample of content for Content1 with a large text, testing, testing, testing, testing, testing, testing, testing, testing, testing, testing, testing, testing, testing
*2
This is a sample of content for Content2 with a large text, testing, testing, testing, testing, testing, testing, testing, testing, testing, testing, testing, testing, testing
*3
This is a sample of content for Content3 with a large text, testing, testing, testing, testing, testing, testing, testing, testing, testing, testing, testing, testing, testing
JavaScript Sample code:
$(function(){
$(".haccordion").haccordion();
});Demo:
Download jquery.haccordion.js code.
Labels: javascript, jquery, programming
simply modify the code, I made an alternative version, I set with the class "visible" for an opened div.
this.opened = jQ("."+params.contentclass,this).filter(".visible").prev();
@anonymous:
for vertical accordions you have an accodion plugin for jQuery
Nice job! Just wrote little more documentattion and please update code where to insert code to start with opened (class "visible")
Thanks!
I would also need a bit more help where to insert the code to start with one div open at page load.
Thanks
REAL EXAMPLE
the changes of the code of the plugin are the minimal that I wrote in another comment. You can check here:
HERE
The visible content is marked with div class = "content visible" <- the photo.
if (p.opened!=this) {
p.opened = this;
jQ(this).next("div."+params.contentclass).animate({
width: params.contentwidth + "px"
}, params.speed);
} else {
p.opened = "undefined";
}
Is there a way for the "contentwidth" to be variable?
contentwidth: 500
The reason is that each content area is different width.
I added ".visible" to one "content" class item
and
this.opened = jQ("."+params.contentclass,this).filter(".visible").prev();
right after "return this.each(function(){"
But it doesn't open by default.
Any tips?
Thanks!
you can set some alternative attribute for each content width and change a bit the code:
div contentwidth="200px" ....
in the code, the line:
width: params.contentwidth + "px"
is changed by:
width: jQ(this).attr("contentwidth")
@mike:
You can use this code modified
Thanks!
Please, I don't know any problem of this plugin, but if you simply say me that not work I can't know more about that, please use Firebug for debugging (maybe your code is wrong) or send me any online example of your code ;-)
You can look this code simple accordion - Work
Open div opened by default - doesn't Work
Thank's
wops!! you are right :-P I forgot to say that in the opened real example I changed same things for usability improvement. The headers contents now a direct link to each page, because I needed get support for no js actived browsers.
Also you need to add, a little css code for visible content, unabling the display:none of the content class.
This is your example modified correctly :-)
Sorry for my bad English :P
My JS and jQuery skills are weak so far. Is there a simple way to tell a specific panel to open on click of a link in the header menu?
Many Thanks,
Mike
I have question though, is there any way to have the 'visible' div perform the scroll action on load. This way users will realize that the content is interactive?
i have a question,
is it possible to place content class in a header class? if no how can i do that?
i am new to js and jquery...
Also, when I try and put flash in the content divs, you can see it slide across the screen - any way around this?
Thanks!
But I use your last script example (show one content when open page) in this site http://www.zeddigitalthailand.com/diorsnow/
and change something (remove link in class header for work)
I want to change event "click" to on mouseover, when on mouseover my content is display. please help me to edit your script
Thank you so much.
modify the haccordion.js as follows:
look for:
jQ("."+params.headerclass,this).click(function(){
change:
.click(function()
to
.mouseover(function()
That's it.
Is there a way to block the active content so if the user clicks on it, it won't close and open again?
Sorry for my English
jquery.haccordion.js
Line 3
main.js
Line 2
I am sorry I am a newbie at this.
Lo primero: como he visto que eres español, te preguntaré en este idioma. Espero que no te importe. ;)
Tengo una duda muy simple: ¿hay alguna manera de hacer que el "header" de la pestaña abierta tenga un fondo diferente?
He intentado modificar el .js para incluir esta opción sin éxito, espero que puedas ayudarme.
Un saludo y muchas gracias.
Puedes hacer lo siguiente:
* después de la línea:
if (p.opened != "undefined"){
añade
$(p.opened).removeClass("active");
* después de la línea:
p.opened = this;
añade
$(this).addClass("active");
La clase active ahora será la clase CSS que tendrá otro aspecto para la pestaña activa ;)
Muchas gracias por contestar tan rápido, no me lo esperaba, jeje. :D
Acabo de hacer eso que me has dicho y me aplica la clase perfectamente, pero no me la elimina una vez que he cambiado de pestaña.
Si la incrusto en el HTML sí que la quita con éxito (es decir, vuelve al estado "off"), cosa que no pasa cuando es agregada a través de JS (con el "addClass").
Gracias de nuevo, de verdad. :D
in order to make one of the slides open initially one can make the modifications indicated by bold face:
jQuery.fn.extend({
haccordion: function(params){
var jQ = jQuery;
var params = jQ.extend({
speed: 500,
headerclass: "handle",
contentclass: "hicerik",
contentwidth: 370,
openone:0
},params);
return this.each(function(index){
jQ("."+params.headerclass,this).each(function(index){
if(index == params.openone){
var p = jQ(this).parent()[0];
p.opened = this;
jQ(this).next("div."+params.contentclass).animate({
width: params.contentwidth + "px"
}, params.speed);
}
}).click(function(){
var p = jQ(this).parent()[0];
if (p.opened != "undefined"){
jQ(p.opened).next("div."+params.contentclass).animate({
width: "0px"
},params.speed);
}
p.opened = this;
jQ(this).next("div."+params.contentclass).animate({
width: params.contentwidth + "px"
}, params.speed);
});
});
}
});
http://www.museumofglass.org/beta.php
One thing however: i'd like to have "next" and "previous" buttons in order to navigate between the panels.. how would you do that?
(so that, while in panel1, if you click a "next" link in the content div, it opens the next panel)
thanx if you can help me!
¿Sabes a qué se puede deber?
Te dejo el enlace para que le eches un vistazo:
http://dreisarquitectos.com/web/
Muchas gracias.
I tried for hours to get this script to work with easing.js - so that the accordion will "bounce" in and out - but I just can't figure out how to do that :(
Can anyone please help me to add the easing.js effects to Sevir's great script here - to the page above?
Thank You.
.haccordion .content{
display: none;
width: 0px;
overflow: hidden;
}
.haccordion .content p {
margin: 0;
padding: 5px;
width: 240px;
}
enjoy! :)
is there an easy way to make the header element change bg colour/bg img etc when it is selected?
Thanks a lot for sharing this nice script. its really good and very light.
But I was wondering if there can be an easy way to make this sliding automatic too. I mean what every general haccordion have is to slide over on mouseover or click. But can we also make the sliding automatic so even if the user don't click the sliding is carried on.
Is this possible with this script, & if possible then how can we do this?
Thanks in advance for your help.
please how much I can do that when opened is "1" to say and when push again to "1" to automatically shut(closed)
I used your plugin on a personal project and added some comments/options
Just check this out : hAccordionI know it's not as simple and compressed as start, but these evolutions could help you in 0.2 version ;)
So, I'm waiting for some new posts on your blog ;)
Clem
I m a newbie !! where I have to put javascript code on blogger and can we use your great plugin for only post tabbs if yes what I must write ?.
Best,
Alex
I changed the expanding parts from a tags to divs and then put the triggering a:s within that div. The triggering a:s are of the same class. Modified the jQuery script so it would work like that instead. Put numbers for a names so I know which one to change. Was tricky and I wouldn't exactly call it orthodox, but it works. :-)