dragging items based on percentage to containment element

后端 未结 3 1628
长情又很酷
长情又很酷 2020-12-16 14:13

Here is what it looks like;

$( \"#box ul li\" ).draggable({
    helper: \"clone\"
});
$( \".item\" ).draggable({containment: \".door\"});

$( \".door\" ).dro         


        
3条回答
  •  时光说笑
    2020-12-16 14:41

    Try this Code :

    $( ".element" ).draggable({
    
        stop: function (){
         var l = ( 100 * parseFloat($(this).css("left")) / parseFloat($(this).parent().css("width")) )+ "%" ;
         var t = ( 100 * parseFloat($(this).css("top")) / parseFloat($(this).parent().css("height")) )+ "%" ;
         $(this).css("left" , l);
         $(this).css("top" , t);
         }
    
    });
    

提交回复
热议问题