0
我有一个垂直方向的垂直导航栏,我想停止在#contact
结束。如果用户滚动备份,它将需要再次重新滚动。 达成此目的的最佳方法是什么?位置:固定导航停止在特定div结束 - 视差滚动&javascript
JavaScript的使用:
$(function() {
$.fn.scrollBottom = function() {
return $(document).height() - this.scrollTop() - this.height();
};
var $el = $('#nav>div');
var $window = $(window);
var top = $el.parent().position().top;
$window.bind("scroll resize", function() {
var gap = $window.height() - $el.height() - 10;
var visibleFoot = 340 - $window.scrollBottom();
var scrollTop = $window.scrollTop()
if (scrollTop < top + 10) {
$el.css({
top: (top - scrollTop) + "px",
bottom: "auto"
});
} else if (visibleFoot > gap) {
$el.css({
top: "auto",
bottom: visibleFoot + "px"
});
} else {
$el.css({
top: 0,
bottom: "auto"
});
}
}).scroll();
});
完美,谢谢。 (还要感谢您抓住这个bug!) – AMC 2013-03-07 23:17:35
@AMC很高兴帮助! – Jesse 2013-03-08 01:28:34