jQM - Responsive design tutorial 2
by Dragan Gaić
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css">
<!DOCTYPE html>
<html>
<head>
<title>jQM Complex Demo</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</head>
<body>
<div data-role="page" id="index" data-theme="a">
<div data-theme="b" data-role="header">
<h3>
First Example
</h3>
</div>
<div data-role="content" id="content">
<ul class="puppys">
<li><a><img src="http://example.gajotres.net/images/001.jpg" alt="001" /></a></li>
<li><a><img src="http://example.gajotres.net/images/002.jpg" alt="002" /></a></li>
<li><a><img src="http://example.gajotres.net/images/003.jpg" alt="003" /></a></li>
<li><a><img src="http://example.gajotres.net/images/004.jpg" alt="004" /></a></li>
<li><a><img src="http://example.gajotres.net/images/005.jpg" alt="005" /></a></li>
<li><a><img src="http://example.gajotres.net/images/006.jpg" alt="006" /></a></li>
<li><a><img src="http://example.gajotres.net/images/007.jpg" alt="007" /></a></li>
<li><a><img src="http://example.gajotres.net/images/008.jpg" alt="008" /></a></li>
<li><a><img src="http://example.gajotres.net/images/009.jpg" alt="009" /></a></li>
<li><a><img src="http://example.gajotres.net/images/010.jpg" alt="010" /></a></li>
</ul>
</div>
</div>
<div data-role="page" id="image" data-theme="a">
<div...
CSS
.ui-content {
padding: 5px !important;
margin: 0 !important;
}
.puppys {
padding: 0;
margin: 0;
list-style: none;
}
.puppys li {
float: left;
width: 50%;
}
.puppys li a {
display: block;
margin: 5px;
}
.puppys li a img, .show {
display: block;
width: 100%;
height: auto;
}
/* 0 - 480px */
@media all and (min-width: 480px){
.puppys li { width: 33.33333333%; }
}
/* 481px - 768px */
@media only screen and (min-width: 768px) {
.puppys li { width: 20%; }
}
/* 769px - 1024px */
@media only screen and (min-width: 1024px) {
.puppys li { width: 16.66666666%; }
}
/* 1025px - 1280px */
@media only screen and (min-width: 1280px) {
.puppys li { width: 14.285714%; }
}
/* 1281px - 1440 */
@media only screen and (min-width: 1440px) {
.puppys li { width: 12.5%; }
}
/* 1441px - 1600px */
@media only screen and (min-width: 1600px) {
.puppys li { width: 11.111111%; }
}
/* 1601px - 1920px */
@media only screen and (min-width: 1920px) {
.puppys li { width: 10%; }
}
JavaScript
$(document).on('pageinit', '#index',function(e, data){
$(document).on('click', '.puppys li a', function() {
handler.image = $(this).find('img').attr('src');
$.mobile.changePage( "#image", { transition: "slide", changeHash: false });
});
});
$(document).on('pagebeforeshow', '#image',function(e, data){
$.mobile.activePage.find('.show').attr('src',handler.image)
});
var handler = {
image: ''
}