- commit
- 3af60e1a2cdb69770a0c15a5f0983aedfec45d93
- parent
- 3ec4d7480585bbba88015569515d4ef35816451b
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-01-04 16:13
refactor: use row/col instead of i/j
Diffstat
| M | sheep.js | 24 | ++++++++++++------------ |
1 files changed, 12 insertions, 12 deletions
diff --git a/sheep.js b/sheep.js
@@ -67,9 +67,9 @@ var drawSheep = function(sheep) {
67 67 }, 10);
68 68 };
69 69
70 -1 var setHelperPosition = function(el, i, j) {
71 -1 el.style.top = 100 / rows * i + '%';
72 -1 el.style.left = 100 / columns * j + '%';
-1 70 var setHelperPosition = function(el, row, col) {
-1 71 el.style.top = 100 / rows * row + '%';
-1 72 el.style.left = 100 / columns * col + '%';
73 73 };
74 74
75 75 grid.addEventListener('mousemove', function(event) {
@@ -77,14 +77,14 @@ grid.addEventListener('mousemove', function(event) {
77 77 var x = (event.clientX - rect.x) / rect.width;
78 78 var y = (event.clientY - rect.y) / rect.height;
79 79
80 -1 var i = Math.floor(y * rows);
81 -1 i = Math.max(0, Math.min(rows - 1, i));
82 -1 var j = Math.floor(x * columns);
83 -1 j = Math.max(0, Math.min(columns - 1, j));
84 -1 var n = rows * j + i + 1;
-1 80 var row = Math.floor(y * rows);
-1 81 row = Math.max(0, Math.min(rows - 1, row));
-1 82 var col = Math.floor(x * columns);
-1 83 col = Math.max(0, Math.min(columns - 1, col));
-1 84 var n = rows * col + row + 1;
85 85
86 86 grid.href = '?sheep=' + n;
87 -1 setHelperPosition(gridHover, i, j);
-1 87 setHelperPosition(gridHover, row, col);
88 88 });
89 89
90 90 var q = parseQuery(location.search);
@@ -95,9 +95,9 @@ if (id) {
95 95 .then(parseQuery)
96 96 .then(drawSheep);
97 97
98 -1 var i = (id - 1) % rows;
99 -1 var j = Math.floor((id - 1) / rows);
100 -1 setHelperPosition(gridFocus, i, j);
-1 98 var row = (id - 1) % rows;
-1 99 var col = Math.floor((id - 1) / rows);
-1 100 setHelperPosition(gridFocus, row, col);
101 101 }
102 102
103 103 document.querySelector('[href="#more"]').addEventListener('click', function(event) {