Bootstrap one-page template with Parallax effect

Bootstrap tutorial / parallax scrolling tutorial. It is no secret that the bootstrap is used on many websites now. This allows to save time and create excellent results in a short period of time. In particular it concerns the markup and styles. Last time, when we wrote about the bootstrap, we received many positive comments, so I decided to prepare another lesson on using this framework today. In order to make it more interesting, we’ll create the demonstration with one of the interesting effects – Parallax. We will see the use of different backgrounds when scrolling the page. In order to understand what we intend to do – please have a look at the demo.

Live Demo

Step 1. HTML

For a start – prepare a skeleton markup:

index.html

01 <!DOCTYPE html>
02 <html lang="en" >
03 <head>
04   <meta charset="utf-8" />
05   <meta name="author" content="Script Tutorials" />
06   <title>Bootstrap one-page template with Parallax effect | Script Tutorials</title>
07   <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
08   <!-- attach CSS styles -->
09   <link href="css/bootstrap.min.css" rel="stylesheet">
10   <link href="css/style.css" rel="stylesheet" />
11 </head>
12 <body>
13   <!--  BODY PAGE CONTENT -->
14   <!-- attach JavaScripts -->
15   <script src="js/jquery-1.10.2.js"></script>
16   <script src="js/bootstrap.min.js"></script>
17   <script src="//maps.google.com/maps/api/js?sensor=true"></script>
18   <script src="js/main.js"></script>
19 </body>
20 </html>

This is the minimal markup which allows us to use the responsive nature of the Bootstrap. Now we can begin with adding new elements to the page.

Top navigation menu

This is the fixed navigation bar. Here is the markup:

01 <!-- navigation panel -->
02 <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
03   <div class="container-fluid">
04     <!-- Brand and toggle get grouped for better mobile display -->
05     <div class="navbar-header">
06       <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-main">
07         <span class="sr-only">Toggle navigation</span>
08         <span class="icon-bar"></span>
09         <span class="icon-bar"></span>
10         <span class="icon-bar"></span>
11       </button>
12       <a class="navbar-brand" href="#">Your Brand Name</a>
13     </div>
14     <div class="collapse navbar-collapse" id="navbar-collapse-main">
15       <ul class="nav navbar-nav navbar-right">
16         <li><a href="#home">Home</a></li>
17         <li><a href="#about">About</a></li>
18         <li><a href="#services">Services</a></li>
19         <li><a href="#information">Information</a></li>
20         <li><a href="#google_map">Contact</a></li>
21         <li><a href="https://www.script-tutorials.com/bootstrap-one-page-template-with-parallax-effect/">Back to tutorial</a></li>
22       </ul>
23     </div><!-- /.navbar-collapse -->
24   </div><!-- /.container-fluid -->
25 </nav>

Basically, this is UL-LI-based menu (as usual). There are links to different sections of the page

Section 1 – Home

The first section is full-sized greeting page:

1 <!-- first section - Home -->
2 <div id="home" class="home">
3   <div class="text-vcenter">
4     <h1>Hello World</h1>
5     <h3>This is bootstrap-based layout</h3>
6     <a href="#about" class="btn btn-default btn-lg">Continue</a>
7   </div>
8 </div>
9 <!-- /first section -->

The greeting text is aligned vertically by center.

Section 2 – About

There are two columns, the image is in the first columnm and centered text is in the right column:

01 <!-- second section - About -->
02 <div id="about" class="pad-section">
03   <div class="container">
04     <div class="row">
05       <div class="col-sm-6">
06         <img src="images/logo.png" alt="" />
07       </div>
08       <div class="col-sm-6 text-center">
09         <h2>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec in sem cras amet.</h2>
10         <p class="lead">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed interdum metus et ligula venenatis, at rhoncus nisi molestie. Pellentesque porttitor elit suscipit massa laoreet metus.</p>
11       </div>
12     </div>
13   </div>
14 </div>
15 <!-- /second section -->

Section 3 – Services

This blue section consists of four elements with glyph icons provided by the bootstrap:

01 <!-- third section - Services -->
02 <div id="services" class="pad-section">
03   <div class="container">
04     <h2 class="text-center">Our Services</h2> <hr />
05     <div class="row text-center">
06       <div class="col-sm-3 col-xs-6">
07         <i class="glyphicon glyphicon-cloud"> </i>
08         <h4>Service 1</h4>
09         <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec in sem cras amet. Donec in sem cras amet.</p>
10       </div>
11       <div class="col-sm-3 col-xs-6">
12         <i class="glyphicon glyphicon-leaf"> </i>
13         <h4>Service 2</h4>
14         <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec in sem cras amet. Donec in sem cras amet.</p>
15       </div>
16       <div class="col-sm-3 col-xs-6">
17         <i class="glyphicon glyphicon-phone-alt"> </i>
18         <h4>Service 3</h4>
19         <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec in sem cras amet. Donec in sem cras amet.</p>
20       </div>
21       <div class="col-sm-3 col-xs-6">
22         <i class="glyphicon glyphicon-bullhorn"> </i>
23         <h4>Service 4</h4>
24         <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec in sem cras amet. Donec in sem cras amet.</p>
25       </div>
26     </div>
27   </div>
28 </div>
29 <!-- /third section -->

Section 4 – Information

This is the second wide section with full-size background, plus, there are two additional blocks (panels):

01 <!-- fourth section - Information -->
02 <div id="information" class="pad-section">
03   <div class="container">
04     <div class="row">
05       <div class="col-sm-6">
06         <div class="panel panel-default">
07           <div class="panel-heading">
08             <h2 class="panel-title">Additional information</h2>
09           </div>
10           <div class="panel-body lead">
11             Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed hendrerit adipiscing blandit. Aliquam placerat, velit a fermentum fermentum, mi felis vehicula justo, a dapibus quam augue non massa. Duis euismod, augue et tempus consequat, lorem mauris porttitor quam, consequat ultricies mauris mi a metus. Phasellus congue, leo sed ultricies tristique, nunc libero tempor ligula, at varius mi nibh in nisi. Aliquam erat volutpat. Maecenas rhoncus, neque facilisis rhoncus tempus, elit ligula varius dui, quis amet.
12           </div>
13         </div>
14       </div>
15       <div class="col-sm-6">
16         <div class="panel panel-default">
17           <div class="panel-heading">
18             <h2 class="panel-title">Additional information</h2>
19           </div>
20           <div class="panel-body lead">
21             Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed hendrerit adipiscing blandit. Aliquam placerat, velit a fermentum fermentum, mi felis vehicula justo, a dapibus quam augue non massa. Duis euismod, augue et tempus consequat, lorem mauris porttitor quam, consequat ultricies mauris mi a metus. Phasellus congue, leo sed ultricies tristique, nunc libero tempor ligula, at varius mi nibh in nisi. Aliquam erat volutpat. Maecenas rhoncus, neque facilisis rhoncus tempus, elit ligula varius dui, quis amet.
22           </div>
23         </div>
24       </div>
25     </div>
26   </div>
27 </div>
28 <!-- /fourth section -->

Section 5 – Contacts and Footer

In fact, there are three elements – the narrow blue service line (to put some extra information), the google map, where you can put your company address (as a pin on the map):

01 <!-- fifth section -->
02 <div id="services" class="pad-section">
03   <div class="container">
04     <div class="row">
05       <div class="col-sm-12 text-center">
06         <h3>Parallax scrolling effect is in action</h3>
07         <h4>The next is the address on Google maps</h4>
08       </div>
09     </div>
10   </div>
11 </div>
12 <!-- /fifth section -->
13 <!-- google map -->
14 <div id="google_map"></div>
15 <!-- /google map -->
16 <!-- footer -->
17 <footer>
18   <hr />
19   <div class="container">
20     <p class="text-right">Copyright &copy; Your Company 2014</p>
21   </div>
22 </footer>
23 <!-- /footer -->

Step 2. CSS

You may have noticed that most elements already received all necessary styles at once. However, we still have to define styles for all new non-standard elements:

css/style.css

01 /* general styles */
02 html, body {
03   height100%;
04   width100%;
05 }
06 /* padded section */
07 .pad-section {
08   padding50px 0;
09 }
10 .pad-section img {
11   width100%;
12 }
13 /* vertical-centered text */
14 .text-vcenter {
15   displaytable-cell;
16   text-aligncenter;
17   vertical-alignmiddle;
18 }
19 .text-vcenter h1 {
20   font-size4.5em;
21   font-weight700;
22   margin0;
23   padding0;
24 }
25 /* additional sections */
26 #home {
27   backgroundurl(../images/home.jpg) no-repeat center center fixed;
28   display: table;
29   height100%;
30   positionrelative;
31   width100%;
32   -webkit-background-size: cover;
33   -moz-background-size: cover;
34   -o-background-size: cover;
35   background-size: cover;
36 }
37 #about {
38 }
39 #services {
40   background-color#306d9f;
41   color#ffffff;
42 }
43 #services .glyphicon {
44   border2px solid #FFFFFF;
45   border-radius: 50%;
46   display: inline-block;
47   font-size60px;
48   height140px;
49   line-height140px;
50   text-aligncenter;
51   vertical-alignmiddle;
52   width140px;
53 }
54 #information {
55   backgroundurl(../images/estate.jpg) no-repeat center center fixed;
56   display: table;
57   height800px;
58   positionrelative;
59   width100%;
60   -webkit-background-size: cover;
61   -moz-background-size: cover;
62   -o-background-size: cover;
63   background-size: cover;
64 }
65 #information .panel {
66   opacity: 0.85;
67 }
68 #google_map {
69   height500px;
70 }
71 footer {
72   padding20px 0;
73 }
74 footer .glyphicon {
75   color#333333;
76   font-size60px;
77 }
78 footer .glyphicon:hover {
79   color#306d9f;
80 }

Step 3. JavaScript

In the end, there is the google map, in order to initialize it (with a predefined address) we have to add the following code:

js/main.js

01 $(document).ready(function (){
02   // create a LatLng object containing the coordinate for the center of the map
03   var latlng = new google.maps.LatLng(-33.86455, 151.209);
04   // prepare the map properties
05   var options = {
06     zoom: 15,
07     center: latlng,
08     mapTypeId: google.maps.MapTypeId.ROADMAP,
09     navigationControl: true,
10     mapTypeControl: false,
11     scrollwheel: false,
12     disableDoubleClickZoom: true
13   };
14   // initialize the map object
15   var map = new google.maps.Map(document.getElementById('google_map'), options);
16   // add Marker
17   var marker1 = new google.maps.Marker({
18     position: latlng, map: map
19   });
20   // add listener for a click on the pin
21   google.maps.event.addListener(marker1, 'click'function() {
22     infowindow.open(map, marker1);
23   });
24   // add information window
25   var infowindow = new google.maps.InfoWindow({
26     content:  '<div class="info"><strong>This is my company</strong><br><br>My company address is here<br> 32846 Sydney</div>'
27   });
28 });

Live Demo

[sociallocker]

download in package

[/sociallocker]


Conclusion

That is all for now, we just finished the layout of our page. I hope that you like the result. Another advantage is the fact that this template is responsive by default, and it means that it looks good at all possible devices (including mobile phones).