모바일 장치의 드래그 앤 드롭 기능을 구현하려고합니다 ... 고정 너비/높이의 컨테이너 div가 있고 그 안에 내용이있는 다른 div가 있지만 크기가 크기보다 큽니다. 부모.뷰포트 컨테이너 내부의 자바 스크립트 드래그 div
내 문제는 draggable div를 클릭하면 움직일 수 있지만 화면에서 touchmove를 시작할 때마다 드래그 할 수있는 요소 위치를 동일하게 유지하는 해결책을 찾지 못한다는 것입니다.
내가 가능한 한 최소한이 유지하려고 또한 나는 jQueryUI
PS를 사용하려는 해달라고 요소는 터치 에뮬레이션 여기
를 사용하여 바탕 화면에 작동 드래그하면 당신은 아닌 현재 위치를 위치의 변화를 얻을 필요가 내 코드
<div class="container">
<div class="draggable">
</div>
</div>
<script>
$(document).on('touchmove','.draggable',function(e){
//Prevent default for mobile devices so the element inside the container can be dragged witouth stopping
//e.preventDefault();
//Calculating the distance where the touch event stopped
var xPos = e.originalEvent.touches[0].pageX;
var yPos = e.originalEvent.touches[0].pageY;
//Moving the draggable element around
$(this).css({
left: xPos + $(this).offset().left + 'px',
top: yPos + $(this).offset().top + 'px'
});
});
</script>
<style>
.container
{
width:200px;
height:200px;
overflow:hidden;
position:relative;
}
.draggable
{
width:1000px;
height:1000px;
background:url('http://th04.deviantart.net/fs71/PRE/f/2014/249/d/f/seraphim_by_alexiuss-d7y4v0o.jpg');
position:relative;
}
</style>
귀하의 바이올린이 비어 있습니다. –
죄송합니다, 내 나쁜 ... – Addonay
draggable 요소를 '마스크'하려면 컨테이너 div가 필요합니까? 나는이 권리가 있니? 내가 알지 못하는 것은 : 할 수있는 요소는 무엇인가? 주위로 드래그 할 수 있습니다. 그리고? JSfiddle은 모바일 이벤트를 에뮬레이션하지 않으므로 드래그 앤 드롭 이후로 삭제해야합니다. 그래서 실제로 테스트 할 수 없습니다. – nocarrier