Skip to content

Instantly share code, notes, and snippets.

@oleksii-leonov
Created August 11, 2012 08:45
Show Gist options
  • Save oleksii-leonov/3322615 to your computer and use it in GitHub Desktop.
Save oleksii-leonov/3322615 to your computer and use it in GitHub Desktop.
Tiny example of auto-scaling for mobile devices
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>Resize test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<meta name="viewport" content="user-scalable=no" />
<style>
html,body{
min-height:100%;
height:100%;
}
body{
padding:0px;
margin:0px;
text-align:center;
}
.cell{
width:10px;
height:10px;
margin: 10px;
background-color:#ccc;
display:inline-block;
}
.cell{
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.cell_clicked{
-webkit-transform: scale3d(0,0,0.5);
-moz-transform: scale3d(0,0,0.5);
-o-transform: scale3d(0,0,0.5);
-ms-transform: scale3d(0,0,0.5);
transform: scale3d(0,0,0.5);
background-color: red;
}
</style>
<script>
function resize(){
body_height = $("body").height();
body_width = $("body").width();
max_size = Math.min(body_height,body_width)
summary_div_heigth = max_size * 0.9;
summary_margins = max_size * 0.1;
div_height = (summary_div_heigth / 4) - 2;
div_margin = (summary_margins / 8) - 2;
$('div.cell').css('height', div_height);
$('div.cell').css('width', div_height);
$('div.cell').css('margin', div_margin);
}
window.onload = function() {
resize();
$('div.cell').click(function() {
$(this).addClass('cell_clicked');
});
};
window.onresize = function() {
resize();
};
</script>
</head>
<body>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<br />
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<br />
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<br />
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment