Tuesday, October 23, 2007

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:

Technorati Tags: , ,

Download jquery.haccordion.js code.

Labels: , ,

25 comments, Post a CommentPosted by posted by SeViR @ 12:44 PM
25 Comments
Oct 23, 2007 4:39:00 PM, Anonymous funbytebitstop said:
This is sooo cool! I just picked up jQuery a week ago and I'm looking at all of the sweet things that are capable. You rock! Great post.  
Nov 5, 2007 7:24:00 PM, Anonymous felix said:
wow really nice! Is there a way to have one content div opened by default?  
Nov 8, 2007 9:55:00 PM, Anonymous Anonymous said:
Great script! Is there anyway to use your script for vertical accordions? Keep up the good work  
Nov 9, 2007 11:07:00 AM, Blogger SeViR said:
@felix:
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  
Nov 13, 2007 6:31:00 PM, Anonymous Alex said:
That's script I looking for!
Nice job! Just wrote little more documentattion and please update code where to insert code to start with opened (class "visible")  
Nov 17, 2007 11:26:00 AM, Anonymous Anders said:
Sweet, just what i was looking for, and easy to customize to my needs!

Thanks!  
Nov 21, 2007 5:06:00 PM, Blogger conica said:
Great code. Thank you. I was looking for this for some time now.
I would also need a bit more help where to insert the code to start with one div open at page load.

Thanks  
Nov 21, 2007 9:57:00 PM, Blogger SeViR said:
A real implementation of haccordion with one visible div by default:

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.  
Nov 22, 2007 2:42:00 PM, Anonymous marco said:
Thank you sevir, nice script. I needed the ability to close an open element though, so I modified it this way:

if (p.opened!=this) {
p.opened = this;
jQ(this).next("div."+params.contentclass).animate({
width: params.contentwidth + "px"
}, params.speed);
} else {
p.opened = "undefined";
}
 
Dec 6, 2007 5:56:00 PM, Blogger Sherman said:
Thanks for the nice menu.

Is there a way for the "contentwidth" to be variable?

contentwidth: 500

The reason is that each content area is different width.  
Jan 9, 2008 10:24:00 PM, Anonymous Mike said:
Sorry about being dense, but I also would like to open one content div by default.

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!  
Jan 9, 2008 11:56:00 PM, Blogger SeViR said:
@sherman:
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  
Jan 11, 2008 10:34:00 PM, Anonymous praxi said:
the open content div by default doesn't work . do you have a idea?

Thanks!  
Jan 11, 2008 11:08:00 PM, Blogger SeViR said:
@praxy:

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 ;-)  
Jan 12, 2008 9:26:00 AM, Anonymous praxi said:
Maybe is my mystake!
You can look this code simple accordion - Work

Open div opened by default - doesn't Work

Thank's  
Jan 12, 2008 10:05:00 PM, Blogger SeViR said:
@praxi:

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 :-)  
Jan 29, 2008 1:44:00 PM, Blogger JaL said:
Hi ! I'm using your script. It so cool. Thanks ! But I still have a question : How could I link to a tab ?
Sorry for my bad English :P  
Feb 6, 2008 12:26:00 AM, Anonymous mike said:
Very nice. I have a development page here: http://www.wiredprojects.com/LBRE/home1.html. I'd like to be able to open a given panel when the user clicks on a specific link in the header bar. Right now the header menu is just a graphic, but will be replaced with links.

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  
Feb 21, 2008 12:45:00 AM, Anonymous Jason V. said:
This script is very helpful! After spending days trying to implement another script, this one took me less then a few hours to get everything working the way I want.

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?  
Mar 8, 2008 2:26:00 PM, Anonymous Temirlan said:
cool, thanks
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...  
Mar 8, 2008 5:32:00 PM, Blogger AKP said:
Very cool, but although I can get your basic example to work, when I try to have one div opened by default (using the code you've linked to here in the comments) it simply doesn't do anything! It seems to break the whole thing, clicking on headers does nothing.

Also, when I try and put flash in the content divs, you can see it slide across the screen - any way around this?

Thanks!  
Mar 16, 2008 5:54:00 PM, Blogger MP3WizarD said:
That's cool script!

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.  
May 5, 2008 1:46:00 PM, Blogger Dips said:
To change event 'click' to on 'mouseover'

modify the haccordion.js as follows:

look for:
jQ("."+params.headerclass,this).click(function(){

change:
.click(function()
to
.mouseover(function()

That's it.  
May 5, 2008 3:37:00 PM, Anonymous Jordao said:
This script is very cool.

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  
May 8, 2008 1:40:00 AM, OpenID ETChevalier said:
I've tried inserting an iframe into one of the content fields but it ends up making all of the other tabs after that one disappear. Any ideas how to fix this? I'll admit that I'm still quite new to using jquery but I imagine there must be a way to make this work.  
Links to this post
This design is under copyright of SeViR CW © 2007