draggable

Home   »   draggable

  $(function () {
        const note = $("#mainContent");
        updatePosition(note);

        note.draggable({cancel: '.inner', scroll: false},{ stop: function () {

              const left = this.offsetLeft;
              const top = this.offsetTop;

              sessionStorage.setItem("left", left);
              sessionStorage.setItem("top", top);
            }
          });

        window.addEventListener("storage", function (e) {
          updatePosition(note);
        },
          false);
      });

      function updatePosition(note) {

        const left = sessionStorage.getItem("left");
        const top = sessionStorage.getItem("top");
        note.css({ left: left + "px", top: top + "px" });

        note[0].offsetTop = top;
        note[0].offsetLeft = left
      }

Leave a Reply

Your email address will not be published.