I’m trying to build a slider-controlled bargraph that uses data from arrays. I’ve managed to get it working using some really messy code here, but I made a much cleaner version here that should work but doesn’t. Actually, it works perfectly as far a capturing data from the arrays, but it breaks when I put in the code that animates the boxes. Then the slider stops moving and the boxes only animate if they have a real number in them (i.e. column 1). I can only post two links, but you can see a version with a working slider if you rename that file to laborslider2_noslide.html.
The thing that confuses me is that, despite the broken slider-handle, the numbers ARE getting passed to the variables (column1, column2, and column3), and the box with a real number in it animates, but none of the variable boxes do a thing. I don’t see why that would be.
I’m new to jquery, so it could be something really dumb. Hopefully it’s something really dumb. 😉
Here’s my code:
<!DOCTYPE html>
<html class="no-js">
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<!--<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>-->
<script type="text/javascript" src="http://img.seiu.org/js/custom-link-tracking.js"></script>
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/jquery-ui.min.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
var updateSizes = function (s) {
var column1 = s[0];
var column2 = s[1];
var column3 = s[2];
return "Column 1: " + column1 + ", Column 2: " + column2 + ", Column 3: " + column3;
},
laborData = Array(14);
laborData[0] = [100, 6, 38];
laborData[1] = [300, 6.5, 38.5];
laborData[2] = [500, 7, 39];
laborData[3] = [6.5, 7.5, 40];
laborData[4] = [7, 8, 40.5];
laborData[5] = [8, 9, 42];
laborData[6] = [8.5, 9.5, 42.5];
laborData[7] = [9, 10, 43];
laborData[8] = [9.5, 10.5, 44];
laborData[9] = [10, 11, 44.5];
laborData[10] = [10.5, 11.5, 45];
laborData[11] = [11, 12, 46];
laborData[12] = [11.5, 12.5, 46.5];
laborData[13] = [12, 13, 47];
$("#slider").slider({
range: "max",
min: 0,
max: 13,
step: 1,
slide: function (event, ui) {
$("#amount").val(updateSizes(laborData[ui.value]));
$("#box").animate({"height":300});
$("#box2").animate({"height":column2});
$("#box3").animate({"height":column3});
}
});
// $("#slider-men").slider({
// range: "max",
// min: 0,
// max: 13,
// step: 1,
// slide: function (e, ui) {
// $("#amount-men").val(updateSizes(laborData[ui.value]));
// }
// });
});
</script>
</head>
<body>
<div id="slider"></div>
<label for="amount">Data:</label> <input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;width:300px;" />
<p>
<div id="box" style="background:#98bf21;height:100px;width:100px;margin:6px; float: left;">
</div>
<div id="box2" style="background:#98bf21;height:100px;width:100px;margin:6px; float: left;">
</div>
<div id="box3" style="background:#98bf21;height:100px;width:100px;margin:6px; float: left;">
</div>
</body>
</html>
So yeah. Any help would be great. I’m stumped.
You have to define the
column1/2/3variables in the global scope because you are setting it in one function and accessing it in another function.I have set up a fiddle and fixed it, take a look. I believe you want the box animation to be in parallel so I have set the queuing of box animation to false
Working demo