표준 API 기능을 넘어서서 JQuery에서 너무 익숙하지는 않지만 내 페이지에는 동일한 코드를 사용하는 많은 수의 스크롤러가 있습니다. 각기 다른 몇 가지 고유 한 설정이 있습니다. (예 : 분리 높이 및 스크롤 한계 및 스크롤 된 현재 횟수). 나는 코드를 반복적으로 사용할 수 있기를 원하지만, 각 참조는 자체 변수 세트를 받는다. 저는 프로토 타입이 제가 생각한 것입니다,하지만 저는 이것에 대해 본 적이있는 예제를 머리에 새겨 넣을 수는 없습니다. 그래서 기본적으로 내가 원하는 것 무엇일반적으로 사용되는 함수에 대한 jquery 프로토 타입
$(document).ready(function() {
var scrollAmt = 50; //distance in pixels;
var scrollableAmt = $('#weblinks .container').outerHeight();
var viewAmt = $('#weblinks').outerHeight();
var maxScroll = Math.ceil((scrollableAmt-viewAmt)/scrollAmt);
var currentItem = 0;
function setScrollButtons(scrollRef,scrollAmount){
}
$("#weblinks .scrollDownBtn").click(function(){
if (currentItem <= maxScroll){
$('#weblinks .container:not(:animated)').animate({'top' : '-='+ scrollAmt + ''},500,function(){
currentItem++
});
} else {
currentItem = 0;
$('#weblinks .container:not(:animated)').animate({'top' : currentItem},500);
}
});
$("#weblinks .scrollUpBtn").click(function(){
if (currentItem > 0){
$('#weblinks .container:not(:animated)').animate({'top' : '+='+ scrollAmt + ''},500,function(){
currentItem--;
});
} else {
$('#weblinks .container:not(:animated)').animate({'top' : currentItem},500);
}
});
});
위의 코드를 모두 수행하는 함수 또는 클래스, 내 생각을 만들지 만에 그것을 사업부 기준을 통과 할 수있다 : 이것은 내 스크롤 코드 #weblinks를 대신 사용하고 스크롤 량을 전달하면이 기능의 여러 인스턴스가 같은 페이지에 함께 존재할 수 있습니다. 누구든지 이것에 대해 가장 좋은 방법에 대해 조언을합니까?
편집 : 각 스크롤러에 대해 항상 존재하는 HTML을 추가했습니다.
<div id="weblinks" class="scrollbar_container">
<div class="customScrollBox">
<div class="container">
<div class="content">
</div>
</div>
<a class="scrollUpBtn" href="javascript:void(0);"></a> <a class="scrollDownBtn" href="javascript:void(0);"></a>
</div>
</div>
어쩌면 HTML의 데모를 보여줄 수 있습니까? 상수는 무엇입니까? (예를 들어 항상'.container','.scrollDownBtn' &'.scrollUpBtn'?) –
확실합니다 - 저는 이것을 추가했습니다 - 상수는 모든 HTML이 될 것입니다. scrollableAmt, viewAmt 및 maxScroll입니다. – mheavers
@ mheavers : 스크롤바 사이에 달라지기를 원하는 조정 가능한 값은 무엇입니까? (어떤 매개 변수에서 일반적으로이 "Addon"에 전달할 것인가? _ scrollbar A_ 대 * scrollbar B_?) –