왼쪽 열에 고정 세로 막대가 있고 오른쪽 열에 페이지 내용이있는 2 열 레이아웃이 있습니다. 나는 또한 바닥 글을 가지고있다. 고정 된 사이드 바를 페이지 콘텐츠 div의 끝 좌표로 바로 스크롤하고 싶습니다.고정 div 세로 스크롤 제한
그러나 사이드 바의 높이가 페이지 콘텐츠의 높이보다 큰 경우 페이지 콘텐츠 div에 새 높이를 자동으로 할당해야합니다. 이 코드는 첫 번째 사례 (사이드 바보다 높은 콘텐츠)에서 작동하지만 두 번째 사례는 페이지를 한 번 더 새로 고침 할 때만 작동합니다 (예를 들어 다른 페이지에서 이러한 종류의 페이지로 이동할 때 스크립트는 내가 페이지를 다시로드 할 때 높이지만, 여기
코드이다)을 수행합니다$(window).load(function(){
var windw = this;
var contentHeight = $('#content').height(); // fetch Сontent div height
var sideHeight = $('.sidebar-nav-fixed').height(); // fetch sidebar div height
$.fn.followTo = function (pos) {
var $this = this,
$window = $(windw);
$window.scroll(function(e){
if ($window.scrollTop() >= pos) {
$this.css({
position: 'absolute',
top: pos
});
} else {
$this.css({
position: 'fixed',
top: 100
});
}
});
};
if (sideHeight > contentHeight) {
$('#content').css ({
height: contentHeight + (sideHeight - contentHeight)
}),
contentHeight = $('#content').height() // Assign a new height to page content div
}
$('.sidebar-nav-fixed').followTo(contentHeight - sideHeight);
});
당신이 어떤 아이디어를 감사가 있다면 정말 기쁠 것입니다!