jQuery UI draggable 요소가 있습니다. 매우 간단합니다. 그것은 다른 div (draggable piece)가 격자로 설정된 div (컨테이너) 일뿐입니다. 문제는 요소를 한 번 이동 한 후에 첫 번째 지점으로 돌아갈 수 없다는 것입니다. 나는 그것이 작동하는 격자 크기를 변경할 수 있지만, 아래 그것을jQuery UI 드래그 가능 처음 지점으로 돌아 가지 않음
관련 JS 몇 가지 요소를 일치하는 것 같이 나는이 그리드에서 작업해야하는 경우 :
$('<div class="slider_wrap"><div class="slider"></div></div>').appendTo('#chart');
$('#chart .slider')
.draggable({
containment:'parent',
grid:[distanceBetweenPoints,0],
opacity: 0.25
})
.bind('mousedown', function(e, ui){
// bring target to front
$(e.target.parentElement).append(e.target);
})
.bind('drag', function(e, ui){
// update coordinates manually, since top/left style props don't work on SVG
e.target.setAttribute('x', ui.position.left);
})
.bind('dragstop',function(e, ui){
//a = true offset of slider piece
var a = ui.position.left + distanceBetweenPoints;
var b = containerWidth;
var c = thePoints.length;
var d = b/c;
var x = a/d;
//Since the points are in an array which starts at 0, not 1, we -1 from the currentPoint
console.log(x)
var currentPoint = Math.round(x)-1;
thisPointIndex = currentPoint;
chart.series[0].data[currentPoint].select(true);
});
어떤 아이디어?
빠른 테스트 후 : 요소를 드래그 할 때 너비 계산에 문제가있는 것 같습니다. 요소를 주위로 드래그 해보십시오. 잠시 후 요소들은 왼쪽으로 돌아 오기 시작합니다. 아마도 문제는 드래그 기능에서 비롯됩니다. 확실하지는 않지만, 정수만 허용하고 실수는 허용하지 않습니다. – kufi