I have a modal box I open with Jquery. When the close buttons is called, the modal box is closed. All works fine, but the more I open and close the modal box, the longer it takes for the modal box to close:
window.closeModal = function () {
modal = $("div.modal-overlay");
windowHeight = $(window).height();
// Until here performance is good
modal.animate({top: windowHeight, }, 800, function () {
// This is the problem
modal.hide();
$("body").css("overflow-y", "scroll");
});
}
I have put console logs on every line, and everything is executed instantly until I hit the modal.animate function. Every time I open a modal, and press the close button, it takes more time until modal.animate starts executing.
Can anyone shed some light please.
@EDIT: I have created a jsfiddle that shows the problem.
Just press open modal, then close modal. Do this 4-5 times to see the delay become bigger
@@EDIT: Something very strange happens.
although openModal is executed once, the iframe.load is executed # times the modal is opened and closed ...
window.openModal = function (url) {
console.log("open start");
modal = $("div.modal-overlay");
modalIframe = $("div.modal-overlay iframe");
windowHeight = $(window).height();
modal.css("bottom", "0");
modalIframe.attr("src", url + "?frame=true");
modalIframe.load(function () {
console.log("open load")
modalIframe.css('height', windowHeight);
modal.show().animate({
top: 0,
}, 800, function () {
$("body").css("overflow-y", "hidden");
});
});
}