我创建了我的第一个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/
常见的选择器是类“滑块”所以'$('。slider')。slajder();' – gillyspy 2013-05-01 01:11:49