Template:Kyoto/myScroll
From 2012.igem.org
(Difference between revisions)
(2 intermediate revisions not shown) | |||
Line 4: | Line 4: | ||
element.css("position","relative"); | element.css("position","relative"); | ||
$(window).scroll(function() { | $(window).scroll(function() { | ||
- | + | var parent = element.parent(); | |
- | + | var scroll_top = $(window).scrollTop(); | |
- | + | var off_top = parent.offset().top; | |
- | + | var _top = scroll_top - off_top; | |
- | + | if(_top > 0) { | |
- | + | element.css("top",_top+"px"); | |
- | + | } else if (_top < 0) { | |
- | + | element.css("top","0px"); | |
- | } | + | } |
- | </script> | + | }); |
+ | }</script> | ||
</html> | </html> |
Latest revision as of 02:43, 26 September 2012