DmitrMakeev commited on
Commit
487ef73
·
verified ·
1 Parent(s): 550239d

Update builder.html

Browse files
Files changed (1) hide show
  1. builder.html +20 -24
builder.html CHANGED
@@ -9,6 +9,7 @@
9
 
10
  <!-- Your Custom CSS -->
11
  <!-- Your Custom CSS -->
 
12
  <style>
13
  .container {
14
  display: flex;
@@ -46,40 +47,35 @@
46
  label: 'Horizontal Block',
47
  content: `
48
  <div class="container">
49
- <div class="item">Item 1</div>
50
- <div class="item">Item 2</div>
51
- <div class="item">Item 3</div>
52
  </div>
53
  `,
54
  attributes: { class: 'gjs-block-section' }
55
  });
56
 
57
- // Example of adding a draggable button
58
- blockManager.add('draggable-button', {
59
- label: 'Draggable Button',
60
- content: `<button class="draggable" draggable="true">Давай</button>`,
61
- attributes: { class: 'gjs-block-section' }
62
- });
63
-
64
  document.addEventListener('DOMContentLoaded', function() {
65
- var button = document.querySelector('.draggable');
66
  var offsetX = 0, offsetY = 0, isDragging = false;
67
 
68
- button.addEventListener('mousedown', function(e) {
69
- isDragging = true;
70
- offsetX = e.clientX - button.offsetLeft;
71
- offsetY = e.clientY - button.offsetTop;
72
- });
 
73
 
74
- document.addEventListener('mousemove', function(e) {
75
- if (isDragging) {
76
- button.style.left = (e.clientX - offsetX) + 'px';
77
- button.style.top = (e.clientY - offsetY) + 'px';
78
- }
79
- });
80
 
81
- document.addEventListener('mouseup', function(e) {
82
- isDragging = false;
 
83
  });
84
  });
85
  </script>
 
9
 
10
  <!-- Your Custom CSS -->
11
  <!-- Your Custom CSS -->
12
+ <!-- Your Custom CSS -->
13
  <style>
14
  .container {
15
  display: flex;
 
47
  label: 'Horizontal Block',
48
  content: `
49
  <div class="container">
50
+ <div class="item"><button class="draggable" draggable="true">Давай</button></div>
51
+ <div class="item"><button class="draggable" draggable="true">Давай</button></div>
52
+ <div class="item"><button class="draggable" draggable="true">Давай</button></div>
53
  </div>
54
  `,
55
  attributes: { class: 'gjs-block-section' }
56
  });
57
 
 
 
 
 
 
 
 
58
  document.addEventListener('DOMContentLoaded', function() {
59
+ var buttons = document.querySelectorAll('.draggable');
60
  var offsetX = 0, offsetY = 0, isDragging = false;
61
 
62
+ buttons.forEach(button => {
63
+ button.addEventListener('mousedown', function(e) {
64
+ isDragging = true;
65
+ offsetX = e.clientX - button.offsetLeft;
66
+ offsetY = e.clientY - button.offsetTop;
67
+ });
68
 
69
+ document.addEventListener('mousemove', function(e) {
70
+ if (isDragging) {
71
+ button.style.left = (e.clientX - offsetX) + 'px';
72
+ button.style.top = (e.clientY - offsetY) + 'px';
73
+ }
74
+ });
75
 
76
+ document.addEventListener('mouseup', function(e) {
77
+ isDragging = false;
78
+ });
79
  });
80
  });
81
  </script>