开发者

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'));
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜