opacity使用jquery获取默认值

时间:2014-08-18 14:21:11

标签: jquery

大家好我有这个脚本,我希望当我点击其他.circle不透明度时返回默认值1
enter image description here

$(this).find('.circle').click(function(){
    $(this).animate({"opacity":"0"},200);
});

3 个答案:

答案 0 :(得分:2)

您可以在制作动画之前将所有.circle元素的不透明度设置为1。例如:

$(this).find('.circle').click(function(){
    $('.circle').css( 'opacity', '1' );
    $(this).animate({"opacity":"0"},200);
});

答案 1 :(得分:1)

试试这个:

var $circles = $(this).find('.circle');
$circles.click(function(){
    $circles.animate({"opacity":"1"},200);

    $(this).animate({"opacity":"0"},200);
});

修改:清理代码

答案 2 :(得分:1)

发布的解决方案会导致当您单击选定的圆圈时,它会闪烁。
如果你想点击一个选定的圆圈,它就不会闪烁,只有当你从一个圆圈切换到另一个圆圈时才会发生变化试试这个:

$(this).find('.circle').click(function(){
    if (!$(this).hasClass('current')){
        $('.circle.current').animate({"opacity":"1"},200);
        $('.circle').removeClass('current');
        $(this).addClass('current');
        $(this).animate({"opacity":"0"},200);
    }
});

Check JSFiddle Demo