Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If i understand you correct, what you try to accomplish in the first place is a two-way communication between the slider and the select element? </p> <p>A possible solution using widget factory to extend the slider and turn the handle into a draggable: <a href="http://jsfiddle.net/Rusln/5NVv8/" rel="nofollow">fiddle</a></p> <pre><code>$.widget("ui.dragSlider", $.ui.slider, { _create: function () { this._super('_create'); var drWidth = this.element.context.clientWidth; var drMax = this.options.max - this.options.min; var drStep = drWidth / drMax; var perc = drStep / drWidth; // turn handle into draggable widget this._handleDraggable(this.handle, drWidth, drMax); // add a basic ruler to the slider this._addVisuals(drMax, drStep); }, // setup handle as a draggable object // wire up draggable event handlers with slider event handlers _handleDraggable: function ($handle, drWidth, drMax) { var that = this; $handle.draggable({ animate: true, axis: "x", containment: "parent", drag: function (event, ui) { // trigger slide event on drag that._trigger("slide", event, ui); }, stop: function (event, ui) { // calculate percentage of handle's position relative to // the slider width var posPer = Math.round(ui.position.left / drWidth * 100); // calculate value for the slider based on handles position var sliderPos = (posPer / 100 * drMax) + that.options.min; // set new value(will trigger change event) that._setOption("value", sliderPos); // trigger slider's stop event that._trigger("stop", "slidestop", ui); } }); }, // add a "basic ruler" _addVisuals: function (drMax, drStep) { for (var i = 0; i &lt;= drMax; i++) { if (i == 0) { $("#value").append("&lt;span&gt;|&lt;/span&gt;"); } else { $("#value").append("&lt;span style='padding-left:" + (drStep - 3) + "px'&gt;|" + "&lt;/span&gt;"); } } }, }); // implementation of custom slider $(document).ready(function () { $("#dragSlider").dragSlider({ min: 1, max: 5, animate: true, slide: function (event, ui) { $("#location").html(ui.position.left); }, change: function (event, ui) { $("#select").val(ui.value); }, }); $("#select").change(function (e) { $("#dragSlider").dragSlider("value", $(this).val()); }); }); </code></pre>
    singulars
    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. 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