最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how can i remove draggable event for div? - Stack Overflow

programmeradmin0浏览0评论

how can i remove draggable event for div?

I want to add new .point to container , then draggablge it, but firstly I want to unbind all draggable events for $('.piont'), how to do it ?

<script type="text/javascript" src=".4.2/jquery.min.js"></script>
<script type="text/javascript" src=".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>

how can i remove draggable event for div?

I want to add new .point to container , then draggablge it, but firstly I want to unbind all draggable events for $('.piont'), how to do it ?

<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery./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>

Share Improve this question asked Oct 9, 2013 at 3:58 mingfish_004mingfish_004 1,4132 gold badges19 silver badges26 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 7

For removing draggable event :

 $( ".selector" ).draggable( 'disable' ); OR
 $( ".selector" ).draggable( 'destroy' );

Further details check jQuery UI API documentation. Click here

For your question:

function unbind_draggable(){
     $('point').draggable( 'destroy' );
     //OR
     $('point').draggable( 'disable' );
}

To remove draggable from all .points, use:

function unbind_draggable(){
    $(".points").draggable("destroy");
}

That will remove all draggable functionality, not just disable it.

See the jQuery UI API.

Although just disabling will work, I don't remend it as it will not clear the RAM that the jQuery draggable is occupying.

Try this out:- http://jsfiddle/adiioo7/chyhf/

JS:-

$(function () {
    $('.point').draggable({
        stop: function (e) {
            alert(1);
        }
    });
});

function unbind_draggable() {
    $('.point').draggable("destroy");
}
 $('.point').droppable('disable');
发布评论

评论列表(0)

  1. 暂无评论