您的位置:首页 > Web前端 > JQuery

js页面滚动浮动层智能定位(jQuery)实现

2013-03-25 16:17 796 查看
如有不明白的地方欢迎加QQ群14670545 探讨
///js页面滚动浮动层智能定位(jQuery)实现
///调用:$("#popfloat").smartFloat($("#mainInfo").width() + 21);
$.fn.smartFloat = function(width_p) {
    var position = function(element) {
        var top = element.position().top, pos = element.css("position");
        $(window).scroll(function() {
            var scrolls = $(this).scrollTop();
            if (scrolls > top) {
                if (window.XMLHttpRequest) {
                    element.css({
                        position: "fixed",
                        width: width_p,
                        top: 0
                    });
                } else {
                    element.css({
                        top: scrolls
                    });
                }
            } else {
                element.css({
                    position: "", //absolute
                    top: top
                });
            }
        });
    };
    return $(this).each(function() {
        position($(this));
    });
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: