我正在尝试获取一个表单,以便在查看器滚动时跟随页面,但是一旦到达容器div的末尾就停止(而不是继续进入页脚)。我得到了它的工作,有点。它跟着我走下页面,但只是一点点,然后停下来。我将放置我正在使用的js,css和html。 1
$().ready(function() {
var $scrollingDiv = $('#scrollingDiv'); //scrolling div
var position = $('#endScroll').position(); // div before you want to stop
var height = $('#page-sidebar').height(); //scrolling div can have dynamic height
var pos = position.top-(height+5);
$(window).scroll(function(){
if($(window).scrollTop() > 200 && $(window).scrollTop() < pos){ //100 is value after it start moving when scrooling
$scrollingDiv.stop()
.animate({'paddingTop':($(window).scrollTop() - 350) + 'px'}, 'slow');
}
});
});
aside#with-sidebar {
width:35%;
float:right;
}
<aside id="with-sidebar">
<div id="scrollingDiv">
<form id="form-appointment">...</form>
</div>
</aside>