У меня есть перетаскиваемый элемент jQuery UI. Это очень просто. Это просто div (контейнер) с другим div внутри (перетаскиваемой частью), установленным в сетку. Проблема в том, что после того, как я переместил элемент, я не могу вернуться к первому пункту. Если я изменяю размер сетки, он работает, но мне нужно, чтобы он работал с этой сеткой, так как она соответствует некоторому элементу под ним
Соответствующий 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);
});
Есть идеи?
Пример:
http://jsbin.com/ucebar