diff --git a/docs/index.html b/docs/index.html index 442e4f5..fcd143b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -40,7 +40,7 @@

dragmove.js

-
+
Drag here
diff --git a/dragmove.js b/dragmove.js index 1cb6463..28783e7 100644 --- a/dragmove.js +++ b/dragmove.js @@ -73,12 +73,8 @@ export const dragmove = function(target, handler, onStart, onEnd) { // If boundary checking is on, don't let the element cross the viewport. if (target.dataset.dragBoundary === "true") { - if (lastX < 1 || lastX >= window.innerWidth - target.offsetWidth) { - return; - } - if (lastY < 1 || lastY >= window.innerHeight - target.offsetHeight) { - return; - } + lastX = Math.min(window.innerWidth - target.offsetWidth, Math.max(0, lastX)); + lastY = Math.min(window.innerHeight - target.offsetHeight, Math.max(0, lastY)); } target.style.left = lastX + "px"; diff --git a/package.json b/package.json index 7c413b3..29f9f16 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@knadh/dragmove", - "version": "0.1.2", + "version": "0.1.3", "description": "A tiny, zero-dependency library for making DOM elements draggable.", "main": "dragmove.js", "files": [