2016-07-29 67 views
0

当用户调整对话框的大小时,它会在几十次以下执行POST。有没有办法阻止它执行$ .post,直到用户释放鼠标按钮。调整大小后的执行帖子(当窗口正在调整大小时不会重复)

dialogClass: 'fixed-dialog', 
    resize: function(event, ui) { 
    $(this).dialog("option", 
     ui.size.height + " x " + ui.size.width); 
    $.post("savelayout.php", { 
     menuheight: ui.size.height, 
     menuwidth: ui.size.width 
    }); 
    } 

编辑:从例子,因为它没有功能删除更新的代码。

+0

http://alvarotrigo.com/blog/firing-resize-event-only-once-when-resizing-is-finished/ –

回答

0

我在这里的解决方案试图检查是否在100毫秒内尝试另一个调整大小。如果没有运行邮政编码。

var act; 
dialogClass: 'fixed-dialog', 
    resize: function(event, ui) { 
    clearTimeout(act); 
    act = setTimeout(function() { 
     $(this).dialog("option", 
     ui.size.height + " x " + ui.size.width); 
     $.post("savelayout.php", { 
     menuheight: ui.size.height, 
     menuwidth: ui.size.width 
     }); 
    }, 100); 
    }; 

另外还有一个jQuery插件:https://github.com/nielse63/jquery.resizeend如果你想要这样一个方法。

+0

所以没有办法使用某种停止功能?我宁可不使用计时器。 – michelle

+0

不..不是我知道了。检查说100毫秒是我最好的选择。 – Iceman

+0

@michelle有一个jQuery插件来做你想做的事 – Iceman