チュートリアルには2つの機能ボタンがありますが、1つのボタンで同じことをしたいので、いくつかの変更を加えてこのチュートリアルに従いました。最初のクリックは完璧に機能しますが、2 回目のクリックを行うと、暗い背景がまだ存在し、消えません。コードと 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);
});