//绑定需要浮动的表头
$(function () {
    $("#floatHead").smartFloat();
});

//智能浮动层函数
$.fn.smartFloat = function () {
    var position = function (element) {
        var top = element.position().top;
        var pos = element.css("position");
        $(window).scroll(function () {
            var scrolls = $(this).scrollTop();
            if (scrolls > top) {
                if (window.XMLHttpRequest) {
                    element.css({
                        position: "fixed",
                        top: 0
                    });
                } else {
                    element.css({
                        top: scrolls
                    });
                }
            } else {
                element.css({
                    position: pos,
                    top: top
                });
            }
        });
    };
    return $(this).each(function () {
        position($(this));
    });
};

 其中floatHead 就是要固定的top导航,如果要让导航一直在最上方,div要加上z-index属性,让它值大点,style="z-index: 100"

posted on 2015-07-09 20:46  haldis  阅读(547)  评论(0编辑  收藏  举报