I have been looking for awhile, and I am just too new with JQuery and javascript to figure out where I am going wrong. Any help will be greatly appreciated. I have the script below, which works great for one element. How can I modify this to work with multiple elements? If I have multiple elements on the page the slider will scroll everything, not just the elements within the one container. I know I could technically just make new variables and new class names for each method but that is messy and I know there has to be a smarter way.
<script type="text/javascript" charset="utf-8">
window.onload = function () {
var container = $('div.sliderGallery');
var ul = $('ul', container);
var itemsWidth = ul.innerWidth() - container.outerWidth();
$('.slider', container).slider({
min: 0,
max: itemsWidth,
handle: '.handle',
stop: function (event, ui) {
ul.animate({'left' : ui.value * -1}, 500);
},
slide: function (event, ui) {
ul.css('left', ui.value * -1);
}
});
};
</script>
And here is the html.
<div class="sliderGallery">
<ul id="audio-downloads">
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
</ul>
<div class="slider">
<div class="handle"></div>
</div>
</div>
<div class="sliderGallery">
<ul id="audio-downloads">
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
<li><a href="#">Audio Title</a></li>
</ul>
<div class="slider">
<div class="handle"></div>
</div>
</div>