From 02e87272dcdcc9441de3249b9389c242a2a69cb8 Mon Sep 17 00:00:00 2001 From: JackieZheng Date: Thu, 26 Oct 2017 12:53:19 +0800 Subject: [PATCH] Update scrollfix.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持body中有内容异步修改操作。 在onScroll() 中重新计算相关数据。 --- js/scrollfix.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/js/scrollfix.js b/js/scrollfix.js index 98ed607..f264400 100644 --- a/js/scrollfix.js +++ b/js/scrollfix.js @@ -20,6 +20,7 @@ placeholder = jQuery('
'), //创建一个jquery对象 optsTop = opts.distanceTop, //定义到顶部的高度 endfix = 0; //开始停止固定的位置 + var originalPosition; var originalOffsetTop; @@ -132,6 +133,25 @@ function onScroll() { lastOffsetLeft = 1; var ScrollTop = $(window).scrollTop(); + + /**Jackie重新计算相关数据start****/ + var documentHeight = $(document).height(); //文档高度 + var startTop = $(opts.startTop), //开始浮动固定对象 + startBottom = $(opts.startBottom), + toBottom, //停止滚动位置距离底部的高度 + ScrollHeight; //对象滚动的高度 + //计算停在底部的距离 + if (!isNaN(opts.endPos)) + { + toBottom = opts.endPos; + } else + { + toBottom = parseFloat(documentHeight - $(opts.endPos).offset().top); + } + //计算需要滚动的高度以及停止滚动的高度 + ScrollHeight = parseFloat(documentHeight - toBottom - optsTop), endfix = parseFloat(ScrollHeight - outerHeight); + /**Jackie重新计算相关数据end**/ + if (opts.bottom != -1) { ScrollTop = ScrollTop + $(window).height() - outerHeight - opts.bottom; } @@ -217,4 +237,4 @@ zIndex: 0, //z-index值 baseClassName: 'scrollfixed' //开始固定时添加的类 }; -})(jQuery); \ No newline at end of file +})(jQuery);