스크롤바가있는 div 요소가 있습니다.이 스크롤바를 상단 또는 하단의 일부 이벤트에서만 스크롤하고 싶습니다.
<div id="scroll_box" style="height:300px; overflow:auto;">
<pre>
Top
.
.
.
.
.
.
.
.
.
.
Bottom
</pre>
</div>
<button id="go_top">Top</button>
<button id="go_bottom">Bottom</button>
내가 이동하는 주요 스크롤 (창) 싶지 않는
내가 시도
$('#scroll_box').animate({scrollTop: $("#scroll_box").offset().top},"fast");
$('#scroll_box').animate({scrollBottom: $("#scroll_box").offset().bottom},"fast");
초심자, 여기에서 처음 검색 한 다음 코드를 맞춰보세요
에 잘못된 값을 사용하고 scrollTop
있으며 scrollBottom
존재하지 않습니다. 또한 click
각 버튼 의 이벤트에 이러한 명령문을 첨부해야 합니다. 그렇지 않으면로드시 실행되고 서로 취소됩니다. 이 시도:
$('#go_top').click(function() {
$('#scroll_box').animate({scrollTop: 0 },"fast");
});
$('#go_bottom').click(function() {
$('#scroll_box').animate({scrollTop: $("#scroll_box pre").height() },"fast");
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다