javascript - How to toggle style in animation using jQuery? -
how can add opacity: 0.5
li
when it's clicked , toggle opacity opacity:1
when clicked again animation?
$('li').on('click', function () { $(this).animate({ opacity: 0.5 }, 500, function () { $(this).toggleclass('completed'); }); });
is there simple solution toggling between classes or need add logic check current opacity , change accordingly? don't want change markup or css through jquery.
we can use math :)
$('li').on('click', function () { $(this).animate({ opacity: (0.5 / $(this).css("opacity")) }, 500, function () { $(this).toggleclass('completed'); }); });
Comments
Post a Comment