Last active
October 18, 2017 19:16
-
-
Save klebercode/f8e94c5f8443c5d725bd199c907deb4b to your computer and use it in GitHub Desktop.
css resize element on scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #header { | |
| width: 100%; | |
| height: 287px; | |
| background-color: #673ab7; | |
| position: absolute; | |
| z-index: 1; | |
| } | |
| #content { | |
| position: relative; | |
| top: 287px; | |
| height: 1000px; | |
| background: yellow; | |
| } | |
| <div id="header"> | |
| My center div... | |
| </div> | |
| <div id="content"> | |
| test | |
| </div> | |
| $(function(){ | |
| var | |
| Node = $('#header'), | |
| BaseHeight = Node.height(); | |
| // To initially run the function: | |
| $(window).resize(); | |
| var $scrollingDiv = Node; | |
| $(window).scroll(function() { | |
| var winScrollTop = $(window).scrollTop() + 0, | |
| newSize = BaseHeight - winScrollTop; | |
| Node.css({ | |
| height: newSize, | |
| "min-height": "70px", | |
| "marginTop": winScrollTop + "px" | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment