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).scroll(function() {
+
     window.onscroll = 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>

Revision as of 01:28, 26 September 2012