slider - Isolating jQuery to only contained elements -


I'm looking for a while, and I'm new to zoom and javascript to know that I'm wrong Where am i Any help will be greatly appreciated. I have the script below, which works very well for an element, how can I modify it to work with many elements? If I have many elements on the page then the slider will scroll everything, not just the elements of a container. I know that I can technically create new variables and new class names for each method, but it is messy and I know that there must be a smart way.

  & lt; Script type = "text / javascript" charset = "UTF-8" & gt; Window.onload = function () {var Container = $ ('div.sliderGallery'); Var al = $ ('ul', container); Var itemwind = ul.innerWidth () - container.outerWidth (); $ ('Slider', container). Slider ({Min: 0, Max: Items Wideth, Handle: '.', 'Stop: Function (Event, UI) {ul.animate ({' left ': ui.value * -1}, 500);}, Slide: Function (Event, UI) {ul.css ('left', ui.value * -1);}}); }; & Lt; / Script & gt;  

And here is html.

  & lt; Div class = "sliderGallery" & gt; & Lt; Ul id = "audio-download" & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; Div class = "slider" & gt; & Lt; Div class = "handle" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "slider gallery" & gt; & Lt; Ul id = "audio-download" & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Audio title & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; Div class = "slider" & gt; & Lt; Div class = "handle" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;  

Update Also saw that You are using window.onload . In JQuery, you get a $ (document) .ready () or its nickname $ (function ()) .

should use each () to run through the elements of Slider Gallery : / P>

  $ (function () {// place your window.Open function wrapper $ ('div.sliderGallery'). Each (function () {var ul = $ ('ul', this ); Var itemsWidth = ul.innerWidth () - $ (this) .outerwidth (); $ ('. Slider', this). Slider ({Minimum: 0, Max: items Wideth, Handle: '.dilled', stop : Function (event, UI) {ul.animate ({'left': ui.value * -1}, 500);}, slide: function (event, u E) {ul.css ('left', ui.value * -1);}})}}}}}  

each callback function, this = in the current dome node. If you need a jQuery object in that context, then use $ (this) .


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -