Support us on YouTube by Subscribing our YouTube Channel. Click here to Subscribe our YouTube Channel

Sunday, 25 May 2014

Bootstrap 3 Grid System

Bootstrap provide Mobile first fluid and responsive grid system that appropriately scales up to 12 columns as the device or view-port size increases.


It provides predefined grid classes for making layouts for different types of devices like phones(<768px), tablet(≥768px), medium sized desktop(≥992px) and large devices(≥200px).


Example: Creating two columns(of equal width) for medium Sized desktop screen

1) Firstly add the .container class in div which sets maximum width and centring of the layout.

2) After Adding container class, Add another div with .row class. As we know that row in the grid is made up of 12 columns and we are going to create two columns having same width than we have to use .col-md-6 class in both div(Sum of Columns 6+6=12). If we use .col-md-6 class in one div and .col-md-7 in another div than the second div wrap up and come in next row(because here no. of columns in row becomes more than 12 i.e.6+7)

<!DOCTYPE html>
<html>
       <head>
              <title>Grid Example</title>
              <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <link href="css/bootstrap.min.css" rel="Stylesheet">
              <style>
             
              </style>
       </head>
       <body>
              <div class="container">
                     <div class="row">
                           <div class="col-md-6"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor eleifend nibh at tristique. In sit amet nibh non dolor tempor tincidunt. Mauris aliquet, lacus in lobortis pulvinar, ligula augue venenatis mi, vel adipiscing orci libero ut nisi. Suspendisse lobortis faucibus enim, a ullamcorper nibh. Aliquam ut diam posuere, ornare augue eget, dignissim massa. Nullam consectetur fermentum enim sit amet hendrerit. Phasellus commodo ornare aliquam. Vestibulum odio enim, pretium in velit semper, faucibus egestas nunc.</p></div>
                           <div class="col-md-6"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor eleifend nibh at tristique. In sit amet nibh non dolor tempor tincidunt. Mauris aliquet, lacus in lobortis pulvinar, ligula augue venenatis mi, vel adipiscing orci libero ut nisi. Suspendisse lobortis faucibus enim, a ullamcorper nibh. Aliquam ut diam posuere, ornare augue eget, dignissim massa. Nullam consectetur fermentum enim sit amet hendrerit. Phasellus commodo ornare aliquam. Vestibulum odio enim, pretium in velit semper, faucibus egestas nunc.</p></div>
                     </div>
              </div>
              <script js="js/bootstrap.min.js"></script>
       </body>

</html>

Preview:


Example: Multiple Grid System

In Multiple grid system, we use two or more than two predefined grid classes for a single div. For easy understanding, we are going to create an example in which we have 3 content boxes(3 div) of same size(33%/33%/33%) for medium sized devices and when we reduce size or access it with Tablet(Small sized device) than our layout changes to 2 div  of equal width(i.e.50%) and one with 100% width below the first two div.
In this Example, we take 3 Div with multiple grid system. Here, we set .col-md-4 class for all the 3 div which makes it to be visible side by side and of same width for the medium sized desktop(≥992px) and for small screen devices like tablet we use .col-sm-6 class for first 2 div so that on small devices first two div come along side by side and .col-sm-12 for third div which makes it to take the entire width of the container.

<!DOCTYPE html>
<html>
       <head>
              <title>Multiple Grid Example</title>
              <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <link href="css/bootstrap.min.css" rel="Stylesheet">
              <style>
             
              </style>
       </head>
       <body>
              <div class="container">
                     <div class="row">
                           <h3>Example of Multiple grid System</h3>
                           <div class="col-sm-6 col-md-4">Some Text here.Some Text here.Some Text here.Some Text here.Some Text here.Some Text here.Some Text here.</div>
                           <div class="col-sm-6 col-md-4">Some Text here.Some Text here.Some Text here.Some Text here.Some Text here.Some Text here.Some Text here.</div>
                           <div class="col-sm-12 col-md-4">Some Text here.Some Text here.Some Text here.Some Text here.Some Text here.Some Text here.Some Text here.</div>
                     </div>
              </div>
              <script js="js/bootstrap.min.js"></script>
       </body>
</html>

Preview for Medium Device desktop:

Preview when viewed on Small Devices Tablet:
Example:Nested Column
For adding Nested column, Add another .row class in the div you want to do partition and then divide the column using .col-md-* as per your need.

<!DOCTYPE html>
<html>
       <head>
              <title>Grid Example</title>
              <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <link href="css/bootstrap.min.css" rel="Stylesheet">
              <style>
             
              </style>
       </head>
       <body>
              <div class="container">
                     <div class="row">
                           <div class="col-md-8">
                                  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor eleifend nibh at tristique. In sit amet nibh non dolor tempor tincidunt. Mauris aliquet, lacus in lobortis pulvinar, ligula augue venenatis mi, vel adipiscing orci libero ut nisi. Suspendisse lobortis faucibus enim, a ullamcorper nibh. Aliquam ut diam posuere, ornare augue eget, dignissim massa. Nullam consectetur fermentum enim sit amet hendrerit. Phasellus commodo ornare aliquam. Vestibulum odio enim, pretium in velit semper, faucibus egestas nunc.</p>
                                  <div class="row">
                                         <div class="col-md-6">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor eleifend nibh at tristique. In sit amet nibh non dolor tempor tincidunt. Mauris aliquet, lacus in lobortis pulvinar, ligula augue venenatis mi, vel adipiscing orci libero ut nisi. Suspendisse lobortis faucibus enim, a ullamcorper nibh.</div>
                                         <div class="col-md-6">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor eleifend nibh at tristique. In sit amet nibh non dolor tempor tincidunt. Mauris aliquet, lacus in lobortis pulvinar, ligula augue venenatis mi, vel adipiscing orci libero ut nisi. Suspendisse lobortis faucibus enim, a ullamcorper nibh.</div>
                                  </div>
                           </div>
                           <div class="col-md-4">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor eleifend nibh at tristique. In sit amet nibh non dolor tempor tincidunt. Mauris aliquet, lacus in lobortis pulvinar, ligula augue venenatis mi, vel adipiscing orci libero ut nisi. Suspendisse lobortis faucibus enim, a ullamcorper nibh.</div>
                     </div>
              </div>
              <script js="js/bootstrap.min.js"></script>
       </body>
</html>

Preview:


Offset:
Offset is required for moving columns towards right side using .col-md-offset-* classes here value of * is in between 1 to 11.

<!DOCTYPE html>
<html>
       <head>
              <title>Grid Example</title>
              <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <link href="css/bootstrap.min.css" rel="Stylesheet">
              <style>
             
              </style>
       </head>
       <body>
              <div class="container">
                     <div class="row">
                           <div class="col-md-3"><p style="background-color:silver;padding:20px;">.col-md-3</p></div>
                           <div class="col-md-3"><p style="background-color:silver;padding:20px;">.col-md-3</p></div>
                           <div class="col-md-3"><p style="background-color:silver;padding:20px;">.col-md-3</p></div>
                           <div class="col-md-3"><p style="background-color:silver;padding:20px;">.col-md-3</p></div>
                     </div>
                     <div class="row">
                           <div class="col-md-3 col-md-offset-3"><p style="background-color:silver;padding:20px;">.col-md-3 .col-md-offset-3</p></div>
                     </div>
                     <div class="row">
                           <div class="col-md-5"><p style="background-color:silver;padding:20px;">.col-md-5</p></div>
                           <div class="col-md-3 col-md-offset-2"><p style="background-color:silver;padding:20px;">.col-md-3 .col-md-offset-2</p></div>
                     </div>
              </div>
              <script js="js/bootstrap.min.js"></script>
       </body>
</html>

Preview:


Hope you like it. Thanks

[Download Source code from Google Drive]

 Protected by Copyscape Web Plagiarism Scanner


Thursday, 15 May 2014

JQzoom Image Magnifier For Zooming Image

In many e-Commerce sites (like flipkart, myntra and so on), we see image zooming effects when the mouse is hovered over the product image. In this article, we will see how to use the JQZoom plugin for adding a zoom effect to images. 
Let's Start
First, go to mind projects and download the JQZoom plug-in. Extract the files and copy js and the CSS folder to the root directory of your project. In the Head tag of your webpage add jQuery and the JQZoom plugin script. You can also attach the latest CDN from the jQuery site rather than using the jquery-1.6.js version of jQuery. Add the jquery.jqzoom.css file to the head tag.

<script src="js/jquery-1.6.js"></script>
<
script src="js/jquery.jqzoom-core.js"></script>
<
link href="css/jquery.jqzoom.css" rel="stylesheet" /> 

In this Example, I will use two jpeg images (one small thumbnail and one larger).One Important thing is that the small picture (the bikethumb.jpg) that will be used as the thumbnail of the scaled version of the larger image. Basically we want that when the mouse is hovered over the small image, the image appears larger. And we will use the class="minipic" in the JQZoom script.
 <a href="images/bike.jpg" class="minipic" title="Cartoon Bike"><img src="images/bikethumb.jpg"title="Bike"/></a>
Now we need to add another script tag to call the jqzoom function. We have passed a parameter in the jqzoom function like zoomtype for the type of effect on mouse hover over the small picture.There are 6 types of ZoomType effects that  we can use. Here we set the lens to true so that the lens becomes visible on the hovering of the mouse over the small picture (in other words bikethumb). We can also adjust the zoom width and zoom height of the magnified image.

<script type="text/javascript">
   $(document).ready(
function () {
      $(
'.minipic').jqzoom({
      zoomType: 
'standard',
      lens: 
true,
      preloadImages: 
false,
      alwaysOn: 
false,
      zoomHeight: 200,
      zoomWidth:200
      });
   });

</
script>

Final preview


[Download Source Code from Google Drive]




Sunday, 11 May 2014

Create Charts in website using Chart.js Javascript library

Recently, I am working on a project in which I have to create some charts and graphs in a website.As we know that Graphs are very useful in displaying data visually rather than displaying data in tables. Using Chart.js, we can draw charts and graphs on webpage using HTML5 canvas element. We can create six types of charts using chart.js

Let's Start
Firstly, we have to go http://www.chartjs.org/ for downloading chart.js Javascript plugin. Clicking on download button will take you to GitHub page from where you can download the archive.


After Extracting the files Chart.js-master.rar file, you will be able to find documentation, examples and chart.js file. Add chart.js javascript library into your document in between head tag.

<script src="js/Chart.min.js"></script>

I am using minified version of chart.js. Add <canvas> element with height,width and unique id.

Example 1:
In first Example we are going to create Pie Chart using chart.js. For creating pie chart, a variable array(named pieChartData) declared which contain value and color properties. Set the values and color depanding upon your chart. 



Chart.js provide various option for changing animation and look. You can change these options according to your wish.
For creating chart, we have to initialize chart class and pass our canvas element and "2D" drawing context and call the pie method.
<!Doctype HTML>
<html>
<head>
    <title>Pie Chart</title>
    <script src="js/Chart.min.js"></script>
</head>
<body>
    <canvas id="pieChartLoc" height="300" width="300"></canvas>
    <script>
        var pieChartData = [
        {
            value: 50,
            color: "lightblue"
        },
        {
            value: 10,
            color: "red"
        },
        {
            value: 40,
            color: "green"
        }
        ]
        var myLine = new Chart(document.getElementById("pieChartLoc").getContext("2d")).Pie(pieChartData);
    </script>
</body>
</html>

Example 2: Creating the Doughnut Chart
Doughnut chart looks much similar to pie chart except they have the centre cut out. Everything is similar to above process except we have to call doughnut method this time.
<!Doctype HTML>
<html>
<head>
    <title>Doughnut Chart</title>
    <script src="js/Chart.min.js"></script>
</head>
<body>
    <canvas id="doughNutChartLoc" height="300" width="300"></canvas>
    <script>
        var DoughNutChartData = [
        {
            value: 50,
            color: "lightblue"
        },
        {
            value: 10,
            color: "red"
        },
        {
            value: 40,
            color: "green"
        }
        ]
        var myDoughnut = new Chart(document.getElementById("doughNutChartLoc").getContext("2d")).Doughnut(DoughNutChartData);
    </script>
</body>
</html>

Preview:

Example 3: Creating the Bar Chart
For creating Bar chart, we have to labels( displayed on x-axis) and datasets( contains information about fillColor, strokeColor and data which is basically value on y-axis)

<!Doctype HTML>
<html>
<head>
    <title>Bar Chart</title>
    <script src="js/Chart.min.js"></script>
</head>
<body>
    <canvas id="barChartLoc" height="300" width="300"></canvas>
    <script>
        var barChartLocData = {
            labels: ["January", "Feburary", "March"],
            datasets: [{ fillColor: "lightblue", strokeColor: "blue", data: [15, 20, 35] }]
        };
        var mybarChartLoc = new Chart(document.getElementById("barChartLoc").getContext("2d")).Bar(barChartLocData);
    </script>
</body>
</html>

Hope you like it. Thanks.
[Download Source Code from Google Drive]


Subscribe us on YouTube

Subscribe Now

Popular Posts

Contact us

Name

Email *

Message *

Like us on Facebook