Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason for this is that you are using <code>$("#slider").slider("value")</code> to retrieve the value. </p> <p>This is <em>not</em> mentioned in the documentation from what I could see, but according to a note in <a href="http://bugs.jqueryui.com/ticket/7837" rel="nofollow">this bug ticket</a>, you should use <code>ui.value</code> to get the <em>new</em> value of the slider and the <code>value</code> method to get the <em>old</em> value of the slider. This explains both of your issues.</p> <p>With that in mind, you have to tweak your code a bit so that you take advantage of <code>ui.value</code> for each slider.</p> <p>I would change two things:</p> <ol> <li><p>Use <code>data-*</code> attributes to designate which slider corresponds to which axis:</p> <pre><code>&lt;div id="slider2" class="slider" data-axis="x"&gt;&lt;/div&gt; &lt;div id="slider3" class="slider" data-axis="y"&gt;&lt;/div&gt; &lt;div id="slider4" class="slider" data-axis="z"&gt;&lt;/div&gt; </code></pre></li> <li><p>Update your <code>slide</code> callback to leverage those attributes:</p> <pre><code>var boxShadow = { x: 0, y: 0, z: 0 }; $('#slider2, #slider3, #slider4').slider({ step: 1, animate: true, slide: function(event, ui) { var axis = $(this).data("axis"); boxShadow[axis] = ui.value; $('#xShadowValue').val(boxShadow.x + ' px'); $('#yShadowValue').val(boxShadow.y + ' px'); $('#zShadowValue').val(boxShadow.z + ' px'); $('#target').css('box-shadow', boxShadow.x + 'px ' + boxShadow.y + 'px ' + boxShadow.z + 'px ' + '#888888'); } }); </code></pre></li> </ol> <p>Basically, keep a simple object that tracks x, y, and z. This object is easily updated using the aforementioned <code>data-*</code> attributes.</p> <p><strong>Example:</strong> <a href="http://jsfiddle.net/t3gva/" rel="nofollow">http://jsfiddle.net/t3gva/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload