0
I’m having trouble "dragging and dropping" the items on my list. I can only hold and drag an item after a single click on it. Does anyone know how I solve this ? Follow my code:
<ul id="sortable">
<li>
<a>
<span class='item' style='cursor: pointer;' onmouseup='atualizaposicao(this.id);' id='1'>Maçã</span>
</a>
</li>
<li>
<a>
<span class='item' style='cursor: pointer;' onmouseup='atualizaposicao(this.id);' id='2'>Biribinha</span>
</a>
</li>
<li>
<a>
<span class='item' style='cursor: pointer;' onmouseup='atualizaposicao(this.id);' id='3'>Astronauta</span>
</a>
</li>
function atualizaposicao(id) {
var id;
$("#sortable").sortable({
start: function(event, ui) {
ui.item.startPos = ui.item.index();
},
update: function(event, ui){
console.log("Posição inicial: " + ui.item.startPos + " Nova posição: " + ui.item.index());
var itens = $(this).children();
console.log("Quantidade de itens: " + itens.length);
itens.each(function(){
var item = $(this).children();
var newVal = $(this).index() + 1;
$(item).children('.index').html(newVal);
});
console.log("***********************************");
var jqxhr = $.ajax({
url: "/aleatoriedades.php",
type: "POST",
data: {
timeout: default_timeout,
id: id,
acao: "salvar_ordem",
novaposicao: ui.item.index(),
seed: random()
}
})
.done(function () {
})
.fail(function (jqXHR, textStatus) {
if (textStatus == 'timeout') {
swal("Tempo Esgotado", "Verifique sua conexão e tente novamente em alguns segundos.", "error")
return;
}
swal("Erro", "Ocorreu um erro de comunicação. Verifique sua conexão.", "error")
});
}
});
$("#sortable").disableSelection();
}
Hello, do not put the solution in the body of the question, can pose as an answer to your own question meanwhile ;)
– Math