jQuery UI Silder opacity dynamic value
I'm using jQuery Ui slider. I want the slider to detect the opacity of the div being clicked on and set that as the initial slider value.
$('.test').click(function() {
$('.test').remo开发者_开发百科veClass('selected');
$(this).addClass('selected')
});
$('#slider').slider({
value: $('.selected').css('opacity'),
min: 0,
max: 1,
step: 0.05,
slide: function(event, ui) {
$('.selected').css({
'opacity': ui.value
})
}
});
Change your click function to be:
$('.test').click(function() {
$('.test').removeClass('selected');
$(this).addClass('selected')
$("#slider").slider("value", $(this).css('opacity'));
});
精彩评论