Windows 8 Sidebar For Website Using jQuery



In this article we will create a sidebar for our website that looks very similar to the Windows 8 sidebar. This sidebar can be used as navigation menu or it can be used to show other options. The specialty of this sidebar is that it is visible only when the user wants it and for the rest of the time it will be hidden. So let's start.

Logic behind Sidebar

I have used the following logic to create the sidebar for my demo:

  • We need a div that is fixed to the right side of the website. Let's call it a container div.
  • The height of the div must be set to the width of the user screen. So that it can be accessed from any point of the right edge.
  • The width of the side bar can be customized deending on the content it carries. In my demo I'm using 6% of the total width as the width of my sidebar.
  • We need another div of the same size as the container div. This div will be used for holding our content. Let's call it an item div.
  • For effects, we will be using the sliding effect of jQuery on both the container and the item div.
  • Initially our side bar will be hidden and it will be shown to the user only when the curser touches the right edge of the website.
  • Now to make the sidebar active, I'm monitoring the mouse movement of the user. The moment the mouse touches the right edge of the web site the X-coordinate of the mouse will be equal to the width of the screen. At that time we can show our sidebar.
  • Again, to hide the sidebar when the curser leaves the sidebar, I'm using the mouse X-coordinates. If the mouse x-coordinate plus the width of the sidebar is less then the width of the screen then we hide the sidebar since the mouse is out of the sidebar.

Coding the sidebar

Add the following HTML to your file:



<meta name="description" content="Locked!final win-8 sidebar." />

<link href="" rel="stylesheet" type="text/css" />

<script src=""></script>

<script src=""></script>



  <div id="ctnr">

    <div id="item">

      <!-- for FB -->

  <a href="" onclick=",

  '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">

    <img id="fb" src="" width="100" height="100" />


 <!-- for twitter -->

  <a href="" onclick=",

  '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"><img id="tw" src="" width="100" height="100" ></a>


  <!-- for G+ -->


  <a href="{}" onclick=",

  '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"><img id="gp"

  src="" width="100" height="100"/></a>





The preceding HTML is for creating a Sharing sidebar. You can use it as in Google Plus, Facebook and Twitter share sidebar. 

Add the following CSS in your file for designing the sidebar.







  height: 100%;









  border-radius:50% ;




  border-radius:50% ;




  border-radius:50% ;






Now comes the difficult part. The jQuery is a bit tricky but if you have gone through the logic then it's a cakewalk.


Add the following jQuery to the file:


  1. $(document).ready(function(){

  2.   $("body").css("width",$(window).width()+"px");

  3. $("body").css("height",$(window).height()+"px");

  4.   $(document).mousemove(function(e){

  5.    if(e.pageX===$(window).width()-1){

  6.       $("#ctnr").show("slide",{direction:"right"},300);

  7.       $("#item").show("slide",{direction:"right"},400);


  9.     }elseif(e.pageX+$("#ctnr").width()<$(window).width()-1){

  10.       $("#ctnr").hide("slide",{direction:"right"},300);  

  11.       $("#item").hide("slide",{direction:"right"},300);  

  12.       }

  13.     });

  14. });

Line numbers 2-3 set the size of the body equal to the size of the screen. This step is important since we have given a container width in percentage.

Line number 4 adds a mouse movement listener on the document to track the mouse movement on the webpage.

Line number 5 checks whether or not the mouse is touching the right edge of the website.

Line number 7 brings in the side bar container.

Line number 8 brings in the side bar items. We have used two different timings for sliding to mimic a Windows 8 menu style.

Line number 9 checks if the mouse is away from side bar. Line numbers 10-11 hides the sidebar and its items.


Live Demo






That's all for this article. I hope you have enjoyed reading this article. In case of any doubt feel free to ask in comments.