다음/prev 버튼으로 움직이는 스크롤 가능 div에 엄지 목록이 있습니다. "다음"버튼을 클릭 할 때마다 첫 번째 보이는 요소의 속성과 일치해야합니다. "이전"버튼을 클릭 할 때마다 마지막으로 표시되는 요소의 속성이 표시됩니다.스크롤 가능한 div에서 첫 번째와 마지막 표시 요소 가져 오기
목록이 끝나면 스크롤 거리가 가변적이기 때문에 수학적으로 어떻게 풀어야할지 모르겠다. 누군가 나를 도울 수 있습니까?
HTML
$<div id="scrollContent">
<ul id="assetList">
<li data-asset-id="15201"></li>
<li data-asset-id="15202"></li>
<li data-asset-id="15203"></li>
...
</ul>
</div>
<a class="next" href="#">next</a>
<a class="prev" href="#">prev</a>
jQuery를
$('a.next').click(function() {
var scrollheight = $("#scrollContent").scrollTop();
$("#scrollContent").animate({scrollTop:scrollheight+375},500,function() {
// get "data-asset-id" of first visible element in viewport
});
});
$('a.prev').click(function() {
var scrollheight = $("#scrollContent").scrollTop();
$("#scrollContent").animate({scrollTop:scrollheight-375},500,function() {
// get "data-asset-id" of last visible element in viewport
});
});
체크 아웃 바이올린 : http://jsfiddle.net/desCodLov/77xjD/10/
감사합니다.
-1? – Thomas