What I've got so far up on codepen:
http://codepen.io/Shane24/pen/cEGsb
I need to save the values that appear in the input boxes when you move the sliders into variables.
Any help greatly appreciated. Thanks.
What I've got so far up on codepen:
http://codepen.io/Shane24/pen/cEGsb
I need to save the values that appear in the input boxes when you move the sliders into variables.
Any help greatly appreciated. Thanks.
The simplest answer to the question is that you can set your variables from the slider's handlers
slide: function( event, ui ) {
$('amount1').val( ui.value );
// This is the value that you just dragged the slider to, there it is,
// in a variable
x = ui.value;
}
Without knowing what you needed I whipped up an example that should show you a working example where I extract the values from the sliders and apply it to the color of the circle in the canvas. This code works with the HTML you posted initially
function drawOnCanvas () {
var rgb =[
$('#slider-1').slider("value"),
$('#slider-2').slider("value"),
$('#slider-3').slider("value")
];
var c = document.getElementById("myCanvas2");
var ctx = c.getContext("2d");
var color = "rgb("+ rgb.join(',') + ")" ;
ctx.fillStyle = color;
ctx.beginPath();
ctx.arc(100, 100, 100, 0, Math.PI*2, true);
ctx.closePath();
ctx.fill();
}
function createSlider(slider, boundTextField) {
slider.slider({
orientation: "vertical",
range: "min",
min: 0,
max: 255,
value: 0,
slide: function( event, ui ) {
boundTextField.val( ui.value );
drawOnCanvas();
}
})
}
$(function() {
createSlider($( "#slider-1" ), $( "#amount1" ));
createSlider($( "#slider-2" ), $( "#amount2" ));
createSlider($( "#slider-3" ), $( "#amount3" ));
});
document.write, what you were doing wrong is that you were executing the code before the HTML was parsed. That last snipper is setting the value in the text field. Hopefully my new answer will help you, but you need to read up a lot more and ask more detailed questions that show what you have tried. This question did not show what you've tried, because you didn't even describe what you wanted (Setting variables doesn't count)
clearRectfollowed by a redrawing of the canvas and you're all set. Should be peanuts really. Use your imagination :)change()functionality; api.jquery.com/change Good luck!