첫 번째 Jquery 콘텐츠 슬라이더 (점 + 슬라이드)를 만들었습니다. 그것은 잘 작동하지만 한 페이지에 두 개의 슬라이더를 구현할 수 없습니다. 두 개의 ID로 함수를 호출하는 방법은 무엇입니까? 난 그냥 JS를 배우기 시작, 그래서 난 그냥 더 잘하고 싶지 않아, 두 슬라이더가 작동해야하는 등 감사한 페이지의 여러 Jquery 간단한 슬라이더
<div class="slider" id="slider">
<div class="slides">
<!-- ... -->
</div>
</div>
<div class="slider" id="slider2">
<div class="slides">
<!-- ... -->
</div>
</div>
JS
(function($) {
$.fn.slajder = function() {
return this.each(function() {
slider = $(this);
slider.prepend('<nav class=\"dots"><span></span><span></span></nav>');
slides = slider.children(".slides");
dots = slider.children(".dots");
dot = dots.children("span");
dot1 = dots.children("span:first-child");
dot2 = dots.children("span:nth-child(2)");
dot1.click(function(){
slides.animate({
top: '10px',
}, 600, function() {
// Animation complete.
});
dot.css("-webkit-box-shadow","#444 0 1px 1px 0px");
$(this).css("-webkit-box-shadow","#444 0 -1px 1px 0px");
});
dot2.click(function(){
slides.animate({
top: '-130px',
}, 600, function() {
// Animation complete.
});
dot.css("-webkit-box-shadow","#444 0 1px 1px 0px");
$(this).css("-webkit-box-shadow","#444 0 -1px 1px 0px");
});
});
};
}(jQuery));
// this one goes at bottom of a page in script tags
$(document).ready(function() {
$('#slider').slajder();
});
그리고 바이올린 - http://jsfiddle.net/lima_fil/CK2jS/
공용 선택자는 클래스 "슬라이더"이므로 $ ('. 슬라이더'). slajder(); ' – gillyspy