I am dealing with animation which includes curtain open and close animation. In that, I used jquery for curtain open and close effect. But I want to change my background opacity when curtain open and close.
For example, I want to change my background image opacity 0 to 1 slowly as per my curtain is opening and similarly, I want to change my background image opacity 1 to 0 slowly when my curtain is closing.
My HTML is as follow :
<div class="container-fluid bgauto"style="opacity:1;">
<img src="img/yc.jpg" id="curtain1a" style="max-width:50%;">
<img src="img/yc.jpg" id="curtain2a" style="max-width:50%;">
</div>
<img id="tfanonoff" class="img-responsive" src="img/fanicon.png" style="max-width:3%;cursor:pointer;"/>
My Jquery is as follows :
$(function () {
var hits = 0;
$('#onoff').click(function () {
if (hits % 2 !== 0) {
$("#curtain1a").animate({ width: 200 }, 2000);
$("#curtain2a").animate({ width: 191 }, 2000, function () { $(".bgauto").fadeTo({ 'opacity': '1' }, 1000); });
}
else {
$("#curtain1a").animate({ width: 30 }, 2000);
$("#curtain2a").animate({ width: 30 }, 2000, function () { $(".bgauto").css({ 'opacity': '0.8' }, 1000); });
}
hits++;
return false;
});
});