I am a novice at this.
I made a demo here: http://jsbin.com/vajafidu/1/edit
But there is something wrong with the code that prevents it from working.
All I want to do is
- the background would fade to black after clicking the button.
- the black background will fade out again clicking the button second time.
Should be easy to do but I think there is some bugs in the codes. Thanks for any helpful advice!!!
HTML
<a href="#" class="btn btn-default" data-toggle="active"> Button </a>
<div id="overlay"></div>
CSS
#overlay {
width: 100%;
height : 100%;
opacity : 0;
background: '#000';
top: 0;
left: 0;
transition: opacity .25s;
-moz-transition: opacity .25s;
-webkit-transition: opacity .25s;
}
.backdrop {
opacity: .4 !important;
}
JS/jQ
$(document).ready(function() {
function toggle() {
$('#overlay').toggleClass('backdrop');
}
$('[data-toggle="active"]').click(toggle);
});