2010-10-19 5 views
0

Je voulais restaurer la position du bloc rouge qui est un div draggable sur le bloc vert et gris et non en bloc bleu il n'est pas travaillé sur le bloc vert mais il a travaillé sur le bloc gris s'il vous plaît aidez-moi ... J'utilise jquery revenir. Le code et LNK sont ci-dessous s'il vous plaît aidez-moi http://galtech.org/testing/drag.phpjquery draggable a un problème à faire glisser?

<style type="text/css"> 
    #draggable { width: 100px; height: 70px; background: red; } 
    #nodrag { width: 200px; height: 270px; background: #00CC66; } 
    </style> 

</head> 
<body > 
<div style="background:#CCCCCC;"> 
    <div id="droppble_blue" style="background:#99CCCC; height:500px; width:620px;"> 
     <div id="draggable" >Drag</div> 
     <div id="nodrag" class="new">no Drag & drop here</div> 
    </div> 
</div> 
</body> 
</html> 
    <script> 
    $(document).ready(function() { 
    $("#draggable").draggable({ revert: "invalid" }); 
    $("#droppble_blue").droppable({drop: function() { alert('dropped');}}); 
    }); 
    </script> 
+0

Est-il est possible pour le bloc vert, car le bloc bleu est parent de la div verte – shahul

Répondre

0

Je ne l'ai pas utilisé jquery draggable mais je

$("#nodrag").droppable({drop: function() { $('#draggable').css({top:'0px',left:'0px'});}}); 

travail?

À plus les choses draggable il n'y a pas de façon évidente à la revert avec des blocs à l'intérieur des éléments valides afin que je ferais le folllowing

$("#draggable").draggable('option', 'start', function(){ 
    //when drag starts save the positions somewhere 
    $(this).data('left',$(this).css('left')).data('top',$(this).css('top')) 
}); 
$("#nodrag").droppable({drop: function(e,ui) { 
    //when dropped on an invalid block move it back to where it was (you could change this to animate to mimic revert) 
    $(ui.draggable) 
    .css({left:$(ui.draggable).data('left'),top:$(ui.draggable).data('top')}); 
}}); 
Questions connexes