Game Development

Wednesday 9 November 2016

Bootstrap Scrollspy Plugin (Advanced)

How To Create a Scrollspy

The following example shows how to create a scrollspy:
<!-- The scrollable area --><body data-spy="scroll" data-target=".navbar" data-offset="50">
<!-- The navbar - The <a> elements are used to jump to a section in the scrollable area --><nav class="navbar navbar-inverse navbar-fixed-top">...  <ul class="nav navbar-nav">    <li><a href="#section1">Section 1</a></li>    ...</nav>
<!-- Section 1 --><div id="section1">  <h1>Section 1</h1>  <p>Try to scroll this page and look at the navigation bar while scrolling!</p></div>...
</body> 

Bootstrap Popover Plugin

The Popover Plugin

The Popover plugin is similar to tooltips; it is a pop-up box that appears when the user clicks on an element. The difference is that the popover can contain much more content.

How To Create a Popover

To create a popover, add the data-toggle="popover" attribute to an element.
Use the title attribute to specify the header text of the popover, and use the data-content attribute to specify the text that should be displayed inside the popover's body:
<a href="#" data-toggle="popover" title="Popover Header" data-content="Some content inside the popover">Toggle popover</a>
<script>$(document).ready(function(){    $('[data-toggle="popover"]').popover(); });</script> 

Bootstrap Tooltip Plugin

The Tooltip Plugin

The Tooltip plugin is small pop-up box that appears when the user moves the mouse pointer over an element:

How To Create a Tooltip

To create a tooltip, add the data-toggle="tooltip" attribute to an element.
Use the title attribute to specify the text that should be displayed inside the tooltip:
<a href="#" data-toggle="tooltip" title="Hooray!">Hover over me</a>
<script>$(document).ready(function(){    $('[data-toggle="tooltip"]').tooltip(); });</script> 

Bootstrap Modal Plugin

The Modal Plugin

The Modal plugin is a dialog box/popup window that is displayed on top of the current page:
<!-- Trigger the modal with a button --><button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal --><div id="myModal" class="modal fade" role="dialog">  <div class="modal-dialog">
    <!-- Modal content-->    <div class="modal-content">      <div class="modal-header">        <button type="button" class="close" data-dismiss="modal">&times;</button>        <h4 class="modal-title">Modal Header</h4>      </div>      <div class="modal-body">        <p>Some text in the modal.</p>      </div>      <div class="modal-footer">        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>      </div>    </div>
  </div></div>

Bootstrap Media Objects

Media Objects

Bootstrap provides an easy way to align media objects (like images or videos) to the left or to the right of some content. This can be used to display blog comments, tweets and so on:
<!-- Left-aligned --><div class="media">  <div class="media-left">    <img src="img_avatar1.png" class="media-object" style="width:60px">  </div>  <div class="media-body">    <h4 class="media-heading">John Doe</h4>    <p>Lorem ipsum...</p>  </div></div>
<!-- Right-aligned --><div class="media">  <div class="media-body">    <h4 class="media-heading">John Doe</h4>    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>  </div>  <div class="media-right">    <img src="img_avatar1.png" class="media-object" style="width:60px">  </div></div>

Bootstrap Forms

Bootstrap's Default Settings

Form controls automatically receive some global styling with Bootstrap:
All textual <input><textarea>, and <select> elements with class .form-control have a width of 100%.

Bootstrap Form Layouts

Bootstrap provides three types of form layouts:
  • Vertical form (this is default)
  • Horizontal form
  • Inline form
Standard rules for all three form layouts:
  • Wrap labels and form controls in <div class="form-group"> (needed for optimum spacing)
  • Add class .form-control to all textual <input><textarea>, and <select> elements

Bootstrap Vertical Form (default)

The following example creates a vertical form with two input fields, one checkbox, and a submit button:
<form>  <div class="form-group">    <label for="email">Email address:</label>    <input type="email" class="form-control" id="email">  </div>  <div class="form-group">    <label for="pwd">Password:</label>    <input type="password" class="form-control" id="pwd">  </div>  <div class="checkbox">    <label><input type="checkbox"> Remember me</label>  </div>  <button type="submit" class="btn btn-default">Submit</button></form>

Bootstrap Inline Form

 
 
 
 
 
In an inline form, all of the elements are inline, left-aligned, and the labels are alongside.
Note: This only applies to forms within viewports that are at least 768px wide!
Additional rule for an inline form:
  • Add class .form-inline to the <form> element
The following example creates an inline form with two input fields, one checkbox, and one submit button:
<form class="form-inline">  <div class="form-group">    <label for="email">Email address:</label>    <input type="email" class="form-control" id="email">  </div>  <div class="form-group">    <label for="pwd">Password:</label>    <input type="password" class="form-control" id="pwd">  </div>  <div class="checkbox">    <label><input type="checkbox"> Remember me</label>  </div>  <button type="submit" class="btn btn-default">Submit</button></form> 

Bootstrap Horizontal Form

A horizontal form stands apart from the other forms both in the amount of markup, and in the presentation of the form.
Additional rules for a horizontal form:
  • Add class .form-horizontal to the <form> element
  • Add class .control-label to all <label> elements
Tip: Use Bootstrap's predefined grid classes to align labels and groups of form controls in a horizontal layout.
The following example creates a horizontal form with two input fields, one checkbox, and one submit button:
<form class="form-horizontal">  <div class="form-group">    <label class="control-label col-sm-2" for="email">Email:</label>    <div class="col-sm-10">      <input type="email" class="form-control" id="email" placeholder="Enter email">    </div>  </div>  <div class="form-group">    <label class="control-label col-sm-2" for="pwd">Password:</label>    <div class="col-sm-10">       <input type="password" class="form-control" id="pwd" placeholder="Enter password">    </div>  </div>  <div class="form-group">     <div class="col-sm-offset-2 col-sm-10">      <div class="checkbox">        <label><input type="checkbox"> Remember me</label>      </div>    </div>  </div>  <div class="form-group">     <div class="col-sm-offset-2 col-sm-10">      <button type="submit" class="btn btn-default">Submit</button>    </div>  </div></form>

Bootstrap Navigation Bar

Navigation Bars

A navigation bar is a navigation header that is placed at the top of the page:
With Bootstrap, a navigation bar can extend or collapse, depending on the screen size.
A standard navigation bar is created with <nav class="navbar navbar-default">.
The following example shows how to add a navigation bar to the top of the page:
<nav class="navbar navbar-default">  <div class="container-fluid">    <div class="navbar-header">      <a class="navbar-brand" href="#">WebSiteName</a>    </div>    <ul class="nav navbar-nav">      <li class="active"><a href="#">Home</a></li>      <li><a href="#">Page 1</a></li>      <li><a href="#">Page 2</a></li>       <li><a href="#">Page 3</a></li>     </ul>  </div></nav>

Inverted Navigation Bar

If you don't like the style of the default navigation bar, Bootstrap provides an alternative, black navbar:

Just change the .navbar-default class into .navbar-inverse:
<nav class="navbar navbar-inverse">  <div class="container-fluid">    <div class="navbar-header">      <a class="navbar-brand" href="#">WebSiteName</a>    </div>    <ul class="nav navbar-nav">      <li class="active"><a href="#">Home</a></li>      <li><a href="#">Page 1</a></li>      <li><a href="#">Page 2</a></li>       <li><a href="#">Page 3</a></li>     </ul>  </div></nav>

Fixed Navigation Bar

The navigation bar can also be fixed at the top or at the bottom of the page.
A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.
The .navbar-fixed-top class makes the navigation bar fixed at the top:
<nav class="navbar navbar-inverse navbar-fixed-top">  <div class="container-fluid">    <div class="navbar-header">      <a class="navbar-brand" href="#">WebSiteName</a>    </div>    <ul class="nav navbar-nav">      <li class="active"><a href="#">Home</a></li>      <li><a href="#">Page 1</a></li>      <li><a href="#">Page 2</a></li>       <li><a href="#">Page 3</a></li>     </ul>  </div></nav> 

Navigation Bar With Dropdown


Navigation bars can also hold dropdown menus.
The following example adds a dropdown menu for the "Page 1" button:
<nav class="navbar navbar-inverse">  <div class="container-fluid">    <div class="navbar-header">      <a class="navbar-brand" href="#">WebSiteName</a>    </div>    <ul class="nav navbar-nav">      <li class="active"><a href="#">Home</a></li>      <li class="dropdown">        <a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1        <span class="caret"></span></a>        <ul class="dropdown-menu">          <li><a href="#">Page 1-1</a></li>          <li><a href="#">Page 1-2</a></li>          <li><a href="#">Page 1-3</a></li>         </ul>      </li>      <li><a href="#">Page 2</a></li>       <li><a href="#">Page 3</a></li>     </ul>  </div></nav>