다른 이미지 위에 이미지가 움직입니다. 어떤 유형의 크기 조정도 적용하지 않으면 올바른 위치에 이미지가 표시되지만 크기 조정을 적용하면 올바른 위치로 이동하지 않습니다. 높이가여전히 크기 조정 후 정확한 너비와 높이를 계산할 수 없음
을 변경이 내가 아는 그 행동이 올바른지 지금까지 jsfiddle
$("#location-default-dropdown").change(function() {
var selection = $(this).val();
$obj = $('#dragable');
var MainImgwidth = $("#backgroundImg").width();
var MainImgheight = $("#backgroundImg").height();
var objWidth = $obj.width();
var objHeight = $obj.height();
//var objWidth = $obj[0].getBoundingClientRect().width;
//var objHeight = $obj[0].getBoundingClientRect().height;
var left = 0;
var top = 0;
if(selection == "TopLeft")
{
left = 0;
top = 0;
}
else if(selection == "TopCenter")
{
left = (MainImgwidth/2) - (objWidth/2);
}
else if(selection == "TopRight")
{
left = MainImgwidth - objWidth;
}
else if(selection == "CenterLeft")
{
top = ((MainImgheight/2) - (objHeight/2));
}
else if(selection == "Center")
{
left = ((MainImgwidth/2) - (objWidth/2));
top = (MainImgheight/2) - (objHeight/2);
}
else if(selection == "CenterRight")
{
left = MainImgwidth - objWidth;
top = (MainImgheight/2) - (objHeight/2);
}
else if(selection == "BottomLeft")
{
top = MainImgheight -objHeight;
}
else if(selection == "BottomCenter")
{
top = MainImgheight -objHeight;
left = (MainImgwidth/2) - (objWidth/2);
}
else if(selection == "BottomRight")
{
top = MainImgheight - objHeight;
left = MainImgwidth - objWidth;
}
$obj.css({'left':left+'px','top':top+'px'});
});