首页 > 其他 > 详细

导航页面头部固定

时间:2015-07-09 21:09:46      阅读:181      评论:0      收藏:0      [点我收藏+]
//绑定需要浮动的表头
$(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"

导航页面头部固定

原文:http://www.cnblogs.com/haldis/p/4634208.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!