Javascript 使用jquery.animate多次调用后动画延迟
在单击div之后,我试图通过调用在单击事件中实现jquery.animate的函数来显示覆盖在整个页面上的内容 几次点击后发生了什么,比如说4次或5次尝试,我开始注意到在点击div和覆盖显示之间有一个延迟,每次点击后这个延迟都会增加 中的详细代码,下面是javascript代码Javascript 使用jquery.animate多次调用后动画延迟,javascript,jquery,css,animation,delayed-execution,Javascript,Jquery,Css,Animation,Delayed Execution,在单击div之后,我试图通过调用在单击事件中实现jquery.animate的函数来显示覆盖在整个页面上的内容 几次点击后发生了什么,比如说4次或5次尝试,我开始注意到在点击div和覆盖显示之间有一个延迟,每次点击后这个延迟都会增加 中的详细代码,下面是javascript代码 function initTemplateEditor(params) { if (typeof params === "undefined") { throw new Error("can't init the
function initTemplateEditor(params) {
if (typeof params === "undefined") {
throw new Error("can't init the editor without params!");
}
var
openEditor = function () {
$(params.templateEditor).animate({
opacity: 1
}, {
duration: 350,
start: function () {
$(params.templateEditor).css({
"display": "block",
"width": $(window).width() - 10,
"height": $(window).height() - 10
});
}
});
},
closeEditor = function () {
$(params.templateEditor).animate({
opacity: 0
}, 350, function () {
$(this).css("display", "none");
});
};
$("#editorClose").click(function () {
closeEditor();
});
openEditor();
}
$(".template-box").click(function () {
initTemplateEditor({
templateEditor: "#templateEditor",
template: this
});
});
每次调用
initTemplateEditor
,您都会使用此函数添加到editor或Close
单击链:
$("#editorClose").click(function () {
closeEditor();
});
如果在函数中添加一个警报
,您将看到它第一次被调用一次,第二次被调用两次,以此类推
将这一行代码添加到紧靠单击
功能的前面,它将解决您的问题:
$("#editorClose").unbind("click");