如何保存多个可拖动jQuery元素的位置

时间:2020-10-30 18:50:01

标签: javascript html jquery css

$(function() {
  var xpos = $(`#${currentid}`).position();
  console.log(xpos.top);
  var sPositions = localStorage.positions || "{}",
    positions = JSON.parse(sPositions);
  $.each(positions, function(id, pos) {
    $("#" + id).css(pos);
    console.log("it saves");
  })
  $(`#${currentid}`).draggable({
    containment: "#body1",
    scroll: false,
    stop: function(event, ui) {
      positions[this.id] = ui.position;
      localStorage.positions = JSON.stringify(positions);
      console.log("it loads");
    }
  });
});

在这种情况下,我必须遍历每个元素,但仍然无法正常工作,请帮助

0 个答案:

没有答案