Change Page Layout Dynamically Using jQuery Layout Plug in

Sounds cool, right? Are you afraid of writing the CSS styles which will suit for all the screens like mobiles, tabs, monitors, and high resolution? As I am not a good designer, I was worried all the time about the resolution issues whenever I used 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 like this plug in, that is why I am sharing some information about it. I hope you will like this.

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. It is pretty simple to use. You can always download the files from the plug in page here.

Using the code

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

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

The next thing we need is some div elements, we can set it as follows.

  1. <div class="ui-layout-center">Content area</div>  
  2. <div class="ui-layout-north">Header</div>  
  3. <div class="ui-layout-south">Footer</div>  
  4. <div class="ui-layout-east">Sidebar</div>  
  5. <div class="ui-layout-west">Sidebar</div>   

Now we will add the scripts.

  1. <script>  
  2.     $(function()  
  3.       {  
  4.         $("body").layout  
  5.         ({  
  6.             applyDefaultStyles: true  
  7.         });  
  8.     });  
  9. </script>   

Here we used applyDefaultStyles:true, this is for ensuring all the required default conditions/options are being applied automatically. Now if you run your page you will be seeing a layout as follows.

Change Page Layout Dynamically

Change Page Layout Dynamically

And this is how your page will look like when you toggle every pane.

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 plug in 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

  1. <!DOCTYPE html>  
  2. <html>  
  3.   
  4. <head>  
  5.     <title>Change Page Layout Dynamically Using jQuery Layout Plug in</title>  
  6.     <meta charset="utf-8" />  
  7.     <link href="layout-default-latest.css" rel="stylesheet" />  
  8.     <script src="jquery-2.2.0.min.js"></script>  
  9.     <script src="jquery.layout-latest.js"></script>  
  10.     <script>  
  11.         $(function()  
  12.           {  
  13.             $("body").layout  
  14.             ({  
  15.                 applyDefaultStyles: true  
  16.             });  
  17.         });  
  18.     </script>  
  19. </head>  
  20.   
  21. <body>  
  22.     <div class="ui-layout-center">Content area</div>  
  23.     <div class="ui-layout-north">Header</div>  
  24.     <div class="ui-layout-south">Footer</div>  
  25.     <div class="ui-layout-east">Sidebar</div>  
  26.     <div class="ui-layout-west">Sidebar</div>  
  27. </body>  
  28.   
  29. </html>   

Conclusion

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

Your turn. What do you think?

A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.

Please see this article in my blog here.

Read more articles on jQuery:


Similar Articles