拖動對話框時會觸發 jQuery UI Drag 事件。
在此處了解有關 jQuery 選擇器和事件的更多信息。
用法:
$(".selector").dialog ( drag:function( event, ui ) { console.log('dragged') },
方法:
- 首先,添加項目所需的jQuery Mobile腳本。
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel = "stylesheet"> <script src = "https://code.jquery.com/jquery-1.10.2.js"> </script> <script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"> </script>
- “打開對話框”按鈕將觸發點擊函數(#gfg),該函數將進一步在對話框(#gfg2)中打開<textarea>。
- drag( event, ui ):鼠標移動時觸發。此拖動附加了一個回調函數,隻要鼠標移動,就會觸發該回調函數。
- 事件:類型->事件
- ui:類型->對象
- 回調函數:函數(事件,用戶接口){console.log(‘dragged’)}
範例1:
HTML
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<link href =
"https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js">
</script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js">
</script>
<script type = "text/javascript">
$(function() {
$( "#gfg2" ).dialog({
autoOpen:false,
drag:function( event, ui ) {
console.log('dragged')
},
});
$( "#gfg" ).click(function() {
$( "#gfg2" ).dialog( "open" );
});
});
</script>
</head>
<body>
<div id = "gfg2" title="GeeksforGeeks">
<textarea>jQuery UI | drag(event, ui) Event</textarea>
</div>
<button id = "gfg">Open Dialog</button>
</body>
</html>
輸出:
相關用法
- jQuery UI dialog resizeStop()用法及代碼示例
- jQuery UI dialog close(event, ui)用法及代碼示例
- jQuery UI Dialog create用法及代碼示例
- jQuery UI dialog dragStart用法及代碼示例
- jQuery UI Dialog dragStop用法及代碼示例
- jQuery UI dialog focus(event,ui)用法及代碼示例
- jQuery UI Dialog open用法及代碼示例
- jQuery UI dialog resize(event,ui)用法及代碼示例
- jQuery UI Dialog resizeStart用法及代碼示例
注:本文由純淨天空篩選整理自taran910大神的英文原創作品 jQuery UI Dialog Drag Event。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。