答案 0 :(得分:2)
问题的最简单答案是您可以从滑块的处理程序设置变量
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;
}
我不知道你需要什么I whipped up an example that should show you a working example我从滑块中提取值并将其应用到画布中圆圈的颜色。此代码适用于您最初发布的HTML
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" ));
});