Template:Kyoto/myScroll
From 2012.igem.org
(Difference between revisions)
Line 3: | Line 3: | ||
function setScroll(element) { | function setScroll(element) { | ||
element.css("position","relative"); | element.css("position","relative"); | ||
- | + | window.onscroll = 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> |
Revision as of 01:28, 26 September 2012