To start, create a new HTML file and include the dhtmlxAccordion code files in it.
dhtmlxAccordion (as any other DHTMLX component) can be used standalone or as a part of the general library.
If you use dhtmlxAccordion standalone you need to include 4 files:
If you use dhtmlxAccordion as a part of the 'dhtmlxSuite' package, you need to include 2 files:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Quick start with dhtmlxAccordion</title> <script src="../codebase/dhtmlxcommon.js"></script> <script src="../codebase/dhtmlxaccordion.js"></script> <link rel="STYLESHEET" type="text/css" href="../codebase/skins/dhtmlxaccordion_dhx_blue.css"> <script src="../codebase/dhtmlxcontainer.js"></script> </head> <body> <script> //here you will place your JavaScript code </script> </body> </html>
On the next step, you should create a DIV container where you then place your accordion.
<div id="box" style="width:300px;height:400px;"></div>
To create a new dhtmlxAccordion object you need to use the next constructor:
var dhxAccord = new dhtmlXAccordion(parentId, skin);
The constructor takes the following parameters:
For our sample accordion we will take an HTML container created on the previous step and the default skin:
var dhxAccord = new dhtmlXAccordion("box");
After you have created an object of dhtmlxAccordion, you can start to add panes to it.
To add a pane to the acccordion, you should use method addItem().
dhxAccord.addItem("a1", "Main Page"); dhxAccord.addItem("a2", "Site Navigation"); dhxAccord.addItem("a3", "Support & Feedback"); dhxAccord.addItem("a4", "Comments");
At first, you should download dhtmlxWindows package from the server into the same folder where previously downloaded packages were put. Then, in the <head> tag of the html file, to specify the full path to the following files:
<head> <script src="[full path to this file]/dhtmlxwindows.js"></script> <link rel="stylesheet" type="text/css" href="[full path to this file]/dhtmlxwindows.css"> <link rel="stylesheet" type="text/css" href="[full path to this file]/dhtmlxwindows_[corresponding_skin_name].css"> </head>
An Accordion object can be attached to any created window on the page. Firstly, you need to create the new base for a set of new windows, a new dhtmlxWindow object for it and set paths for window's image files.
<script> var dhxWins = new dhtmlXWindows(); dhxWins.setImagePath("[full path to this directory]/codebase/imgs/"); var w1 = dhxWins.createWindow("w1", 10, 10, 320, 360); </script>
The parameters of the createWindow() method are as follows:
The window will invoke the base for dhtmlxAccordion and will return the handler for the Accordion object itself. So, you should write only the following line of code:
var dhxAccord = w1.attachAccordion();
At first, you should download dhtmlxLayout package from the server into the same folder where previously downloaded packages were put. Then, in the <head> tag of the html file, to specify the full path to the following files:
<head> <script src="[full path to this file]/dhtmlxlayout.js"></script> <link rel="stylesheet" type="text/css" href="[full path to this file]/dhtmlxlayout.css"> <link rel="stylesheet" type="text/css" href="[full path to this file]/dhtmlxlayout_[corresponding_skin_name].css"> </head>
We need to create an object where dhtmlxLayout will be placed later. In this example, the object is a <div> element, placed in the <body> tag:
<div id="parentId" style="position:absolute; width:600px; height:400px;"></div>
The next step - create a new dhtmlXLayoutObject and place it after the <div> element (object) that we've just created:
var dhxLayout = new dhtmlXLayoutObject("parentId", "3L", "dhx_black");
The second argument in dhtmlXLayoutObject() is the code of the Layout's pattern.
The third argument is optional, and it indicates the name of the skin chosen for the Layout. If this argument is not indicated, the component will be created with the default skin (dhx_skyblue).
And only then, you should write the following line of code in order to attach an Accordion to the chosen layout's cell (let it be the first cell “a”):
var dhxAccord = dhxLayout.cells("a").attachAccordion();
<head> <script> var dhxAccord; function doOnLoad() { dhxAccord = new dhtmlXAccordion(); } </script> </head> <body onload="doOnLoad();"> ... </body>