Template:Code
From 2013.igem.org
(Difference between revisions)
Line 44: | Line 44: | ||
float: left; | float: left; | ||
background-color: #E0F8E0; | background-color: #E0F8E0; | ||
+ | position: fixed; | ||
width:200px; | width:200px; | ||
} | } | ||
Line 85: | Line 86: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
- | $(function() { | + | $(function() { |
- | + | // Stick the #nav to the top of the window | |
- | + | var nav = $('#side_menu_items'); | |
- | + | var navHomeY = nav.offset().top; | |
- | + | var isFixed = false; | |
- | + | var $w = $(window); | |
- | + | $w.scroll(function() { | |
- | + | var scrollTop = $w.scrollTop(); | |
- | + | var shouldBeFixed = scrollTop > navHomeY; | |
- | + | if (shouldBeFixed && !isFixed) { | |
- | + | nav.css({ | |
- | + | position: 'fixed', | |
- | + | top: 0, | |
- | + | left: nav.offset().left, | |
- | + | width: nav.width() | |
- | + | }); | |
- | + | isFixed = true; | |
- | + | } | |
- | + | else if (!shouldBeFixed && isFixed) | |
- | + | { | |
- | + | nav.css({ | |
- | + | position: 'static' | |
- | + | }); | |
- | + | isFixed = false; | |
- | + | } | |
- | + | }); | |
- | + | }); | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
var links = document.getElementsByTagName( 'a' ); | var links = document.getElementsByTagName( 'a' ); | ||
Line 124: | Line 119: | ||
}; | }; | ||
</script> | </script> | ||
+ | |||
</head> | </head> | ||
</html> | </html> |
Revision as of 15:20, 2 July 2013