0

Как можно при клике захватить элемент, а при двойном клике отпустить его?

div {
  background: crimson;
  width: 100px;
  height: 100px;
}
<div id="block"></div>

1

1 ответ 1

1

Вариант jQuery:

$("#block").click(function() {
  $(document).on("mousemove", function(e) {
    var $this = $("#block");
    $this.offset({
      top: e.pageY - $this.height() / 2,
      left: e.pageX - $this.width() / 2
    });
  });
}).dblclick(function(e) {
  $(document).unbind("mousemove");
});
div {
  background: crimson;
  width: 100px;
  height: 100px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="block"></div>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.