min*_*004 1 javascript jquery jquery-ui
如何删除div的可拖动事件?
我想在容器中添加新的.point,然后draggablge它,但首先我要取消绑定所有可拖动的$('.piont')事件,怎么做?
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.8.2/jquery-ui.js"></script>
<style type="text/css">
*{margin:0;padding:0}
.container{
margin:50px;
width:100px;
height:100px;
border:1px solid #777;
position:relative
}
.point{
width:20px;
height:20px;
background-color:tan;
position:absolute;
}
</style>
<script type="text/javascript">
$(function(){
$('.point').draggable({
stop: function (e){
alert(1);
}
});
});
function unbind_draggable(){
// how can unbind draggable for .point?
}
</script>
<div class="container">
<div class="point"></div>
<div class="point"></div>
<div class="point"></div>
<div class="point"></div>
</div>
<button onclick="unbind_draggable()">unbind_draggable</button>
Run Code Online (Sandbox Code Playgroud)

要删除可拖动事件:
$( ".selector" ).draggable( 'disable' ); OR
$( ".selector" ).draggable( 'destroy' );
Run Code Online (Sandbox Code Playgroud)
进一步的细节检查jQuery UI API文档.点击这里
对于你的问题:
function unbind_draggable(){
$('point').draggable( 'destroy' );
//OR
$('point').draggable( 'disable' );
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3995 次 |
| 最近记录: |