CSS 속성으로 인해 div 태그로 스크롤하는 데 너무 많은 여백이 있습니다. 그래서 jquery가이 문제를 해결하는 가장 좋은 해결책이라고 생각합니다.Jquery로 Div ID로 스크롤
이것이 작동하지 않는 이유가 확실하지 않아 Js와 Jquery에 대해 매우 익숙합니다. 도움을 주시면 큰 도움이됩니다.
다음은 Js에 대한 간략한 설명입니다. 나는 당신의 DIV ID가 컨테이너에있을 때 ('컨테이너)
jQuery(document).ready(function($){
var prevScrollTop = 0;
var $scrollDiv = jQuery('div#container');
var $currentDiv = $scrollDiv.children('div:first-child');
var $sectionid = 1;
var $numsections = 5;
$scrollDiv.scroll(function(eventObj)
{
var curScrollTop = $scrollDiv.scrollTop();
if (prevScrollTop < curScrollTop)
{
// Scrolling down:
if ($sectionid+1 > $numsections) {
console.log("End Panel Reached");
}
else {
$currentDiv = $currentDiv.next().scrollTo();
console.log("down");
console.log($currentDiv);
$sectionid=$sectionid+1;
console.log($currentDiv.attr('id'));
var divid =$currentDiv.attr('id');
jQuery('#container').animate({scrollTop:jQuery('#'+divid).position().top}, 'slow');
}
}
else if (prevScrollTop > curScrollTop)
{
// Scrolling up:
if ($sectionid-1 == 0) {
console.log("Top Panel Reached");
}
else {
$currentDiv = $currentDiv.prev().scrollTo();
console.log("up");
console.log($currentDiv);
$sectionid=$sectionid-1;
var divid =$currentDiv.attr('id');
jQuery('html, body').animate({scrollTop:jQuery('#'+divid).position().top}, 'slow');
}
}
prevScrollTop = curScrollTop;
});
});
확인 : http://stackoverflow.com/questions/6677035/jquery-scroll-to-element –
코드를 수정하여 관련 부분을 제시하면 사람들이 귀하의 질문에 답변하는 데 도움이됩니다. –