2016-07-29 65 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

相關問題