Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why you don't want something like <a href="http://jsfiddle.net/ostapische/fFtKx/" rel="nofollow">this</a>?<br> When you drag a slider years slides too.<br> HTML: </p> <pre><code>&lt;div id="yearsHolder" style="height: 20px !important; overflow-x: hidden; position: relative;"&gt;&lt;/div&gt; &lt;div id="slider" style="width: 200px;"&gt;&lt;/div&gt; &lt;div id="amount"&gt;&lt;/div&gt; </code></pre> <p>Javascript (main is the <code>slide</code> event): </p> <pre><code>var yearTextWidth = 50; var yearsPerText = 5;// every 5 years appears text $(function() { $("#slider").slider({ min: 1900, max: 2000, step: 1, disabled: false, animate: true, orientation: "horizontal", range: false, value: 1900, create: function(event, ui) { var slider = $(this); var value = slider.slider("value"); $("#amount").html(value); var sliderWidth = slider.width(); var yearTextsLength = Math.floor(sliderWidth / yearTextWidth);// left or equal var yearsHolder = $("#yearsHolder"); yearsHolder.css("width", (sliderWidth + yearTextWidth) + "px !important"); var min = $(this).slider("option", "min"); var max = $(this).slider("option", "max"); var currentYear = min; var yearHolder; while (currentYear &lt;= max) { yearHolder = $("&lt;div&gt;&lt;/div&gt;"); yearHolder.css("text-align", "left"); yearHolder.css("position", "absolute"); yearHolder.css("left", (((currentYear - min) / yearsPerText) * yearTextWidth) + "px"); yearHolder.css("width", yearTextWidth + "px !important"); yearHolder.html(currentYear); yearsHolder.append(yearHolder); currentYear += yearsPerText; } }, slide: function(event, ui){ var value = ui.value; $("#amount").html(value); var slider = $(this); var min = slider.slider("option", "min"); var max = slider.slider("option", "max"); var width = slider.width(); $.each($("#yearsHolder div"), function(index, element){ var div = $(element); var currentLeft = parseInt(div.css("left")); var currentYear = parseInt(div.html()); div.css("left", ((value - min) * (width / (max - min)) + ((currentYear - min) - (value - min)) * (yearTextWidth / yearsPerText)) + "px"); }); } }); }); </code></pre> <p><strong>UPD</strong><br> You can set <code>yearsPerText = 1</code> to show current year near a slider.</p>
    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.
    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