Template:Kyoto/myScroll

From 2012.igem.org

(Difference between revisions)
(Created page with "<html> <script type="text/javascript"> function setScroll(element) { element.css("position","relative"); $(window).scroll(function() { var parent = e...")
 
(6 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 parent = element.parent();
-
                    if($(window).scrollTop() > parent.offset().top && (parent.height() + parent.position().top - 30) > ($(window).scrollTop() + element.height())) {
+
        var scroll_top = $(window).scrollTop();
-
                        var scroll_top = $(window).scrollTop() - parent.offset().top;
+
        var off_top = parent.offset().top;
-
                        element.css("top",scroll_top+"px");
+
        var _top = scroll_top - off_top;
-
                    } else if ($(window).scrollTop() < (parent.offset().top)) {
+
        if(_top > 0) {
-
                        element.css("top","0px");
+
            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