我按照本教程 进行了一些更改,因为本教程有两个功能按钮,但我想用一个按钮做同样的事情。第一次点击很完美,但是当我第二次点击时,深色背景仍然存在并且不会消失,这是代码和 JSfiddle:
$(document).ready(function () {
var isOpen = false;
function showOverlayBox() {
//if box is not set to open then don't do anything
if (isOpen == false) return;
// set the properties of the overlay box, the left and top positions
$('#help-content').toggle();
// set the window background for the overlay. i.e the body becomes darker
$('.bgCover').css({
display: 'block',
width: $(window).width(),
height: $(window).height(),
});
}
function doOverlayOpen() {
//set status to open
isOpen = true;
showOverlayBox();
$('.bgCover').css({
opacity: 0
}).animate({
opacity: 0.5,
backgroundColor: '#000'
});
// dont follow the link : so return false.
$('#help').attr("class", "helpc");
return false;
}
function doOverlayClose() {
//set status to closed
isOpen = false;
$('#help-content').css('display', 'none');
// now animate the background to fade out to opacity 0
// and then hide it after the animation is complete.
$('.bgCover').css({
opacity: 0
}).animate({
opacity: 0
}, function () {
$(this).hide();
});
$('#help').attr("class", "help");
}
// if window is resized then reposition the overlay box
$(window).bind('resize', showOverlayBox);
// activate when the link with class launchLink is clicked
$('.help').click(doOverlayOpen);
// close it when closeLink is clicked
$('.helpc').click(doOverlayClose);
});