Pinkie
Pinkie

Reputation: 10256

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').removeClass('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
        })
    }
});

Upvotes: 1

Views: 507

Answers (1)

Avitus
Avitus

Reputation: 15968

Change your click function to be:

$('.test').click(function() {
    $('.test').removeClass('selected');
    $(this).addClass('selected')
    $("#slider").slider("value", $(this).css('opacity'));
});

Upvotes: 1

Related Questions