Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hero Zoom on Scroll
<header class="zoom">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/927610/pkRkVCm.jpg">
</header>
<main role="main">
<div class="content">
<h1>Zoom Hero Image on Scroll</h1>
<a href="http://webdesignerwall.com/tutorials/how-to-add-icon-fonts-to-any-element-with-css" alt="webdesignerwall.com" target="_blank">View Tutorial</a>
<p>Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Maecenas sed diam eget risus varius blandit sit amet non magna. Nulla vitae elit libero, a pharetra augue. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.</p>
<p>Curabitur blandit tempus porttitor. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.</p>
<footer>
<p>A <a href="http://www.webdeisgnerwall.com" alt="web designer wall" target="_blank">webdesignerwall.com</a> Tutorial</p>
</footer>
</div>
</main>
$(window).scroll(function() {
var scroll = $(window).scrollTop();
$(".zoom img").css({
transform: 'translate3d(-50%, -'+(scroll/100)+'%, 0) scale('+(100 + scroll/5)/100+')',
//Blur suggestion from @janwagner: https://codepen.io/janwagner/ in comments
//"-webkit-filter": "blur(" + (scroll/200) + "px)",
//filter: "blur(" + (scroll/200) + "px)"
});
});
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
/* --- General Pen Styles --- */
body{
font-family: Georgia, serif;
color: #333;
font-size: 1.4rem;
line-height: 2rem;
}
a{color: #000;}
h1{
font-size: 2.6rem;
line-height: 2.6rem;
}
.content{
margin: 0 auto;
max-width: 90%;
width: 720px;
}
main{
padding: 1% 0;
position: relative;
background: #f5f5f5;
box-shadow: 0px -10px 60px rgba(0,0,0,0.25);
height: 100%;
}
footer p{
font-size: .8rem;
font-weight: bold;
color: #ccc;
}
footer a{color: #ccc;}
/* --- Important Pen Styles --- */
.zoom{
overflow: hidden;
padding-bottom: 55%;
}
.zoom img{
position: fixed;
top: 0%;
left: 50%;
max-width: 200%;
transform: translateX(-50%);
/* Thanks @bastian_fiessinger. Use when activating blur effect:
will-change: -webkit-filter, filter, transform; */
}
@media (max-width: 667px) {
h1{
font-size: 1.8rem;
line-height: 2.6rem;
text-align: left;
}
.content{
margin: 0 auto;
max-width: 90%;
width: 100%;
height: 100%;
text-align: justify;
}
.zoom{
overflow: hidden;
padding-bottom: 75%;
}
}
<link href="https://dl.dropbox.com/s/w9ywuzlvqvv7kln/codepen-template.scss" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.