javascript - jquery slider snap to all values instead of jumping to a clicked value -


i have utilized jquery ui(http://jqueryui.com/slider/#steps) , made changes code fit needs.

i'm trying make this,

enter image description here

right i'm working functionalities , work on later user interface.

i'm trying make slider snap values instead of jumping mouse clicked. example handle on slider on left end, when click slider on right end jump mouse clicked, don't want happen. want slider follow values on array array[0] array[19] or array[19] array[0].

var valmap = [10,9,8,7,6,5,4,3,2,1,1,2,3,4,5,6,7,8,9,10]; //10x optical zoom wide/tele 

when handle on left end array[0] equal 10 , when click on array[19] right end should not jump array[19] should start array1 9 click again array[2] 8 , etc.

it should in order , not jumping.

10,9,8,7,6,5,4,3,2,1 <--- left end zoom out(wide)

1,2,3,4,5,6,7,8,9,10 <--- right end zoom in(tele)

even when click parts of slider should follow order , not jump mouse clicked.

slider sample zooming in

& = slider handle

^ = mouse click

w & - - - - - - - - - - - - - - ^ - - - - t    10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10   w - & - - - - - ^ - - - - - - - - - - - - t    10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 

see how handle moved 10 9 , not jump 6 mouse clicked.

click again:

w - - & - - - - - - - - - - - - - - - - - t    10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 

slider sample zooming out

w - - - - ^ - - - - - - - - - - - - - - & t    10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10   w - - - - - - - - - - - ^ - - - - - - & - t    10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 

click again:

w - - - - - - - - - - - - - - - - - & - - t    10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 

here's code:

<html lang="en"> <head>   <meta charset="utf-8" />   <title>jquery ui slider - snap increments</title>   <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />   <script src="http://code.jquery.com/jquery-1.9.1.js"></script>   <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>   <link rel="stylesheet" href="/resources/demos/style.css" />   <script>    $(document).ready(function() {     var valmap = [10,9,8,7,6,5,4,3,2,1,1,2,3,4,5,6,7,8,9,10]; //10x optical zoom wide/tele     var slider = $( "#slider" ).slider({       disabled: false,       animate: true,       min: 0,       max: valmap.length-1,       values: [10],       change: function( event, ui ) {         $( "#zomlevel" ).val(valmap[ui.values[0]] + "x");         slider.slider("option", "disabled", true);         slider.slider("option", "animate", "slow");         settimeout(enable, 3000);       },       stop: function(event, ui){         if(ui.value == 10){           alert("default zoom");         }         if(ui.value < 10){            wide();           }         if(ui.value > 10){            tele();         }       }     }); $( "#zomlevel" ).val( "x" + $( "#slider" ).slider( "value" ) );     function wide(){       $.post(                  'cntr_l.php',                  { cmd: "out" },                  function( data ){                    $( 'body ').append( data );                  });     }      function tele(){       $.post(                  'cntr_l.php',                  { cmd: "in" },                  function( data ){                    $( 'body ').append( data );                  });     }      function enable(){       slider.slider("option", "disabled", false);     }    });    </script> </head> <body>  <p>   <label for="zoom">zoom controller(w/t)</label>   <input type="text" id="zomlevel" style="border: 0; color: #f6931f; font-weight: bold;" /> </p>  <div id="slider"></div>   </body> </html> 

how can make work that?

here's jsfiddle: http://jsfiddle.net/endl3ss/sqscv/


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -