Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery.animate多次调用后动画延迟_Javascript_Jquery_Css_Animation_Delayed Execution - Fatal编程技术网

Javascript 使用jquery.animate多次调用后动画延迟

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

在单击div之后,我试图通过调用在单击事件中实现jquery.animate的函数来显示覆盖在整个页面上的内容 几次点击后发生了什么,比如说4次或5次尝试,我开始注意到在点击div和覆盖显示之间有一个延迟,每次点击后这个延迟都会增加

中的详细代码,下面是javascript代码

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");