그래서 일부 정의 된 앵커 태그 위로 마우스를 가져 가면 div의 내용을 부드럽게 스크롤 할 수있는 스크립트가 있습니다.내가 가지고있는 스크롤 스크립트를 어떻게 하나의 기능으로 바꿀 수 있습니까?
스크립트를 복사하고 사이트의 다른 부분에서이 기능을 사용할 때마다 선택한 요소와 함수 이름을 일부 변경해야하는 것이 아닌지 궁금합니다. 그런 다음에 값을 전달할 수있는 함수로 변환할까요?
다음은 JSFiddle에 대한 링크입니다. 그러면 JSFiddle의 기본 동작 방식에 대한 아이디어를 얻을 수 있습니다. 가능한 모든 도움에 감사드립니다!
http://jsfiddle.net/s5mgX/365/
var step = 50;
var scrolling = false;
// Wire up events for the 'scrollUp' link:
$("#scrollUp").bind("click", function (event) {
event.preventDefault();
// Animates the scrollTop property by the specified
// step.
$("#feed").animate({
scrollTop: "-=" + step + "px"
});
}).bind("mouseover", function (event) {
scrolling = true;
scrollContent("up");
}).bind("mouseout", function (event) {
scrolling = false;
});
$("#scrollDown").bind("click", function (event) {
event.preventDefault();
$("#feed").animate({
scrollTop: "+=" + step + "px"
});
}).bind("mouseover", function (event) {
scrolling = true;
scrollContent("down");
}).bind("mouseout", function (event) {
scrolling = false;
});
function scrollContent(direction) {
var amount = (direction === "up" ? "-=1px" : "+=1px");
$("#feed").animate({
scrollTop: amount
}, 1, function() {
if (scrolling) {
scrollContent(direction);
}
});
}
//second scroll controller //
var step = 50;
var scrolling = false;
// Wire up events for the 'scrollUp' link:
$("#twoScrollUp").bind("click", function (event) {
event.preventDefault();
// Animates the scrollTop property by the specified
// step.
$("#feedTwo").animate({
scrollTop: "-=" + step + "px"
});
}).bind("mouseover", function (event) {
scrolling = true;
twoScrollContent("up");
}).bind("mouseout", function (event) {
scrolling = false;
});
$("#twoScrollDown").bind("click", function (event) {
event.preventDefault();
$("#feedTwo").animate({
scrollTop: "+=" + step + "px"
});
}).bind("mouseover", function (event) {
scrolling = true;
twoScrollContent("down");
}).bind("mouseout", function (event) {
scrolling = false;
});
function twoScrollContent(direction) {
var amount = (direction === "up" ? "-=1px" : "+=1px");
$("#feedTwo").animate({
scrollTop: amount
}, 1, function() {
if (scrolling) {
twoScrollContent(direction);
}
});
}
당신은 그것에서 jQuery 플러그인을 만들고 싶어? – powtac
그래, 꽤 많이. 나는 스크립트를 꽤 자주 호출 할 것이고, 플러그인으로 변환하는 방법을 모르겠다. –