Skip to content

Instantly share code, notes, and snippets.

@cprerovsky
Last active December 18, 2015 04:59
Show Gist options
  • Select an option

  • Save cprerovsky/5729751 to your computer and use it in GitHub Desktop.

Select an option

Save cprerovsky/5729751 to your computer and use it in GitHub Desktop.
3d perspective animation test for my blog
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<style>
body {
margin-top: 250px;
height: 2000px;
background: url(http://images3.pixlis.com/background-image-stripes-and-lines-seamless-tileable-floral-white-lily-white-232etr.png) repeat;
}
.wrap {
-webkit-perspective: 1200px;
height: 200px;
}
.wrap h1, .wrap span {
display: inline;
font-family: Verdana;
font-size: 50px;
background-color: rgba(30, 30, 30, 0.6);
color: white;
padding: 15px;
position: absolute;
-webkit-transform: rotateY( -35deg );
text-shadow: -1px -1px #666;
}
.wrap span {
font-size: 20px;
background-color: rgba(130, 130, 130, 0.6);
padding: 10px;
margin-top: 100px;
}
h1.shadow {
margin: 40px 0 0 10px;
color: rgba(0, 0, 0, 0.0);
background: rgba(30, 30, 30, 0.3);
text-shadow: none;
-webkit-box-shadow: 0px 0px 10px 5px rgba(30, 30, 30, 0.3);
}
.wrap span {
display: none;
}
</style>
</head>
<body><div class="wrap">
<h1 class="shadow">The Agile Truth</h1>
<h1>The Agile Truth</h1>
<span>Thoughts on agile development</span>
</div>
<script type="text/javascript">
$(function () {
var initPer = per = -30,
oldScrollTop = 0,
scrollTop = 0;
function calcPer() {
scrollTop = $(document).scrollTop();
scrollDistance = scrollTop - oldScrollTop;
per = per + parseInt(scrollDistance / 1.5, 10);
oldScrollTop = scrollTop;
return per > 200 ? 200 : per;
}
function setPer(per) {
$('.wrap').css('-webkit-perspective-origin-y', per + '%');
}
function updatePer() {
setPer(calcPer());
};
updatePer();
$(document).on('scroll', function () {
updatePer();
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment