Here is what it looks like;
$( \"#box ul li\" ).draggable({
helper: \"clone\"
});
$( \".item\" ).draggable({containment: \".door\"});
$( \".door\" ).dro
I've found a solution;
$( ".item" ).draggable({
containment: ".door",
stop: function( event, ui ) {
$(this).css("left",parseInt($(this).css("left")) / ($(".door").width() / 100)+"%");
$(this).css("top",parseInt($(this).css("top")) / ($(".door").height() / 100)+"%");
}
});
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);
}
});
Little bit updated version of all above:
$('.element').draggable({
containment: 'parent',
stop: function( event, ui ) {
var $elm = $(this);
var pos = $elm.position(),
parentSizes = {
height: $elm.parent().height(),
width: $elm.parent().width()
};
$elm.css('top', ((pos.top/parentSizes.height) * 100) + '%').css('left', ((pos.left/parentSizes.width) * 100) + '%');
}});