Jquery UI sliders - 2 working together to calculate an amount -
i've got 2 jquery sliders , when them working break. first slider measures weight, , second exercise. i'm trying code final value, 'outcome' displays outcome of both.
when 1st weight slider increases, outcome value. when 2nd exercise slider increases, final outcome goes down. i'm using simple number values until head around it, how them working together?
$(function() { $( "#slider_1" ).slider({ value:100, min: 0, max: 500, step: 50, slide: function( event, ui ) { $( "#amount" ).val( "+" + ui.value ); } }); $( "#amount" ).val( "+" + $( "#slider_1" ).slider( "value" ) ); }); $(function() { $( "#slider_2" ).slider({ value:100, min: 0, max: 9, step: 5, slide: function( event, ui ) { $( "#amount2" ).val( "+" + ui.value ); } }); $( "#amount2" ).val( "$" + $( "#slider_2" ).slider( "value" ) ); });
i have created simple example jsfiddle. think 1 of issues initialization of second slider have changed default 0 , have step of 1.
html
<div id="slider_1"></div> <div id="slider_2"></div> <input id="amount"></input>
javascript
$(function() { var weightslidervalue = 0; var exerciseslidervalue = 0; function changevalue(){ var currentslidervalue = weightslidervalue - exerciseslidervalue; $( "#amount" ).val( currentslidervalue ); } $( "#slider_1" ).slider({ value:100, min: 0, max: 500, step: 50, slide: function( event, ui ) { weightslidervalue = ui.value; changevalue(); } }); $( "#slider_2" ).slider({ value:0, min: 0, max: 9, step: 1, slide: function( event, ui ) { exerciseslidervalue = ui.value; changevalue(); } });
});
each slider move sets corresponding variable calls changevalue. function create more complex function relate 2 value moment have subtracted exercise weight. hope helps
Comments
Post a Comment