Mobile-first development
JavaScript library
DOM Manipulation
Event handling
Animation
Ajax calls (getting data)
Select element
$('selector')
Get attribute
$('#my-svg').attr('height') // height of svg
$('#my-p').css('font-size') // css properties
$('#my-div').text() // text in div
$('input').val() // value of input
Set attribute
$('#my-svg').attr('height', '400px')
$('p').css('font-size', '20px')
$('#my-input').val('input value')
$('#my-div').text('The new text')
Graceful degradation v.s. progressive enhancement
Easier to add than remove
Do the hard work up front
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head;-->
</head>
Set device width
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://.../bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://.../bootstrap-theme.min.css">
<!-- jquery library, required for bootstrap JS to run -->
<script src="https://.../jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://.../bootstrap.min.js"></script>
Read in libraries
Horizontal sections as rows
Vertical sections as columns
Column 1
Column 2
Column 3
Row 1
Row 2
There are 12 columns in the grid
Elements can take up many columns
Row 1:
Row 2:
Row 3:
Specify columns based on screen-size
<body>
<div class="container">
<div class="row">
<div class="col-md-6">6 columns on a medium screen</div>
<div class="col-md-6">6 columns on a medium screen</div>
</div>
</div>
</body>
Set columns for desired device
Create elements
@media screen and (max-width: 300px) {
body {
background-color: lightblue;
}
}
Media queries
Conditional styles
div[class^="col-"] {
border:1px solid gray;
}
Cool trick
Apply to all divs with class col-*
<nav class="navbar navbar-default">
<div class="container">
<!-- Header for mobile -->
<div class="navbar-header">
....
</div>
<!-- Screen navigation elements -->
<div id="navbar" class="navbar-collapse collapse">
...
</div>
</nav>
Use bootstrap's built in navigation classes
Use lists to build controls
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
$(".nav li").on("click", function() {
$(".nav li").removeClass("active");
$(this).addClass("active");
});
Assign actions with jQuery
What does this do:
This looks nice
<div class="btn-group" role="group" aria-label="...">
<button type="button" class="btn btn-default">Left</button>
<button type="button" class="btn btn-default">Middle</button>
<button type="button" class="btn btn-default">Right</button>
</div>
Add title properties to elements
<button type="button" title="Hover info">Hover</button>
Activate tooltips
$('selector').tooltip()
But not at all
Like alerts
Bootstrap challenge (due Thursday before class)