Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Change Page Layout Dynamically Using JQuery Layout Plug-In

DZone's Guide to

Change Page Layout Dynamically Using JQuery Layout Plug-In

In this post, we are going to see how we can change the layout of a page dynamically, without writing any CSS styles for the page. Sounds cool, right? Read on and see how it's done.

· Web Dev Zone
Free Resource

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

In this post, we are going to see how we can change the layout of a page dynamically, without writing any CSS styles for the page. Sounds cool, right? Are you afraid of writing the CSS styles which will suit for all screens like mobile, tablets, monitors, high resolution? As I am not a good designer, I', worried all the time about resolution issues whenever I use any custom styles. Here we will be using a jQuery plugin called jQuery Layout and we have options to set our Footer, Side bar, Header, and many more. Personally, I liked this plugin, which is why I am sharing some information about it.

Download Source Code

You can always download the source code here:

Background

I came to know about this plugin when I was searching for some page layout for my application. Then I just installed it and started using. It is pretty simple to use. You can always download the files from the plugin page here.

Using the Code

To start with this plugin, the first thing you are required to do is add the necessary references. We are going to use three references, jQuery, jquery.layout-latest.js, layout-default-latest.css.

<link href="layout-default-latest.css" rel="stylesheet" />
 <script src="jquery-2.2.0.min.js"></script>
 <script src="jquery.layout-latest.js"></script> 

The next thing we need are some div elements; we can set them as follows.

<div class="ui-layout-center">Content area</div>
 <div class="ui-layout-north">Header</div>
 <div class="ui-layout-south">Footer</div>
 <div class="ui-layout-east">Sidebar</div>
 <div class="ui-layout-west">Sidebar</div>

Now, we will add the scripts.

<script>
 $(function () {
 $("body").layout({
 applyDefaultStyles:true
 });
 });
 </script>

Here, we uses applyDefaultStyles:true, this is for ensuring all the required default conditions/options are being applied automatically. Now if you run your page, you will see a layout like the following.

Change Page Layout Dynamically

Change Page Layout Dynamically

And, this is how your page will look like when you toggle panes.

Change Page Layout Dynamically WHen Toggling

Change Page Layout Dynamically When Toggling

The following are the key features offered by the development team as they have mentioned in their plugin home page here.

  • Simple to use: powerful but simple syntax is easy to learn
  • Unlimited layout capabilities: 5 regions per layout – unlimited nesting
  • Dozens of options: every aspect is customizable, globally and by region
  • Total CSS control: dozens of auto-generated classes create ANY UI look
  • Extensible: callbacks, methods, and special utilities provide total control
  • Custom buttons: integrates with your own buttons for a custom UI look
  • Collapsable: each pane can be closed, using any UI animation you want
  • Hidable: panes can be completely hidden, either on startup or at any time
  • Resizable: each pane can be resized, within automatic or specified limits
  • Slidable: panes can also ‘slide open’ for temporary access
  • Headers & Footers: each region has unlimited headers or footers
  • Hotkeys: can use the cursor-keys and/or define custom hotkeys
  • Use any elements: use divs, iframes or any elements you want as a ‘pane’
  • Compatible with UI widgets: integrates with jQuery widgets and plug-ins
  • demo mode: set applyDefaultStyles option for a fully functional layout

The developers have provided many demos of how we can use this plugin, you can always check those here.

That is all, now you can start using this plugin. See the complete code below.

Complete Code

<!DOCTYPE html>
<html>
<head>
 <title>Change Page Layout Dynamically Using jQuery Layout Plug in</title>
 <meta charset="utf-8" />
 <link href="layout-default-latest.css" rel="stylesheet" />
 <script src="jquery-2.2.0.min.js"></script>
 <script src="jquery.layout-latest.js"></script> 
 <script>
 $(function () {
 $("body").layout({
 applyDefaultStyles:true
 });
 });
 </script>
</head>
<body>
 <div class="ui-layout-center">Content area</div>
 <div class="ui-layout-north">Header</div>
 <div class="ui-layout-south">Footer</div>
 <div class="ui-layout-east">Sidebar</div>
 <div class="ui-layout-west">Sidebar</div>
</body>
</html>

Conclusion

Did I miss anything that you may think which is needed? Have you ever wanted to do this requirement? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:
jquery ,responsive design ,web dev ,css

Published at DZone with permission of Sibeesh Venu, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}