Skip to content

Instantly share code, notes, and snippets.

@yeyus
Created June 28, 2013 07:16
Show Gist options
  • Save yeyus/5883015 to your computer and use it in GitHub Desktop.
Save yeyus/5883015 to your computer and use it in GitHub Desktop.
Orientation detection for full-screen parallax
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Orientation Test</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
<script src="orientation.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="wrapper">
<h1>Orientation test</h1>
<div class="parallax">
<div class="rotate-overlay"><h2>Rotate your device!</h2></div>
<div class="parallax-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
</div>
</body>
</html>
$(document).ready(function () {
$(window).resize(function() {
var isPortrait = Modernizr.mq('only screen and (orientation : portrait)'),
isBigScreen = Modernizr.mq('(min-width: 768px)');
if(!isBigScreen&&isPortrait) {
$('.rotate-overlay').css('display', 'block');
$('.parallax-content').removeClass('full-screen');
} else if(isBigScreen) {
$('.rotate-overlay').css('display', 'none');
} else {
$('.rotate-overlay').css('display', 'none');
$('.parallax-content').addClass('full-screen');
}
});
});
body, html, #wrapper {
margin: 0;
padding: 0;
}
.parallax {
position: relative;
width: 100%;
}
.parallax .rotate-overlay {
display: none;
position: absolute;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.8);
text-align: center;
z-index: 1000;
}
.parallax .parallax-content {
position: relative;
width: 100%;
height: 100%;
background: #fef;
font-size: 1.5em;
font-family: helvetica;
padding: 20px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
z-index: 100;
}
.parallax .parallax-content.full-screen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1001;
background: #f4f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment