This is a simple block of plain old JavaScript that will allow developers to easily turn html div's into resizable div's by simply adding one of two classes to each, resulting in a draggable splitter line on the relevant sides:
resizable-e
resizable-s
These classes will add a splitter
By default the class will also save and restore the container sizes; this is saved to the browsers localStorage (not cookie) and is unique to each web page (not including page arguments).
Prerequisites for this to work are that the div's are:
container
It should also be noted that because the divider drag-bars are overlayed on top of the panels, you will need to use padding to avoid their contents from being partially hidden by the dividers.
open_in_new See the methodfish demos or play with your own version using jsfiddle.net.
html
For situations where you wish to have static panels within the container, problems might arise with the sizing of the resizables if the static panel is before a resizable, so you are advised to continue to include resizable-* classes on those static panels, but include the classname noselect
so that no dragger is included for those panels.
e.g.
html
If you have some !important
mark in your css, e.g.
css
By default, the panel sizes will be saved each time they are changed.
This storage will by default go to the browser localStorage relating to the calling page, and used onload to restore the sizes - but there is a risk that the original sizes will be seen before this restore occurs. Should you run into problems, you can use the javascript MFPanels().reset()
to reset the panel sizes.
Tricks can then be used to hide the containers before making them visible after the MFPanels().init() has completed using a class you need to set up named invisible
, which MFPanels will then remove on completion. Note, using display:none
will cause problems with sizing calculations.
css
html
Use a preset variable named _MFPanelsInitCallback
and set to your function that will do what is required to do further manipulation on the panels if required (note, this must be set before declaring the mfpanel.js file),
e.g.
js
Use a preset variable named _MFPanelsHandleUpCallback
and set to your function that will do what is required to do further manipulation on the panels if required when a dragger handle is released (via touch or mouse),
e.g.
js
The class can optionally use browser cookies instead of browser localStorage to retain the panel sizes; doing this will mean that server side processing could see the last used panel sizes before the page is delivered to the browser.
This can be done using another preset variable named _MFPanelsUseCookies
, e.g.
js
Server side processing can read the cookie and use this in your panel html:
php
php
info Important: Note, if you use this method then it is important to include the default width
To set the color of the panel dragger, simply adjust the paneldragger
class
css
Also see
articles/Implementing-a-Monaco-Editorsquarearticles/iConnectionTestsquarearticles/javascript-camerasquarearticles/list-editsquarearticles/minifierssquarearticles/opayosquarearticles/table-drag-sortersquarearticles/typewatchsquareprojects/MFCalendarPopupsquareprojects/MFChartColumnsquareprojects/MFColorPickersquareprojects/MFColorPickerBasicsquareprojects/MFColumnGradientsquareprojects/MFFloatawayMsgsquareprojects/MFPanelssquareprojects/MFSelectorsquare
Comments
New Comment