Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "easy-float", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Easy Float", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -11,3 +11,6 @@ # Install | ||
const options = { | ||
const easyFloat = new EasyFloat(); | ||
const container = document.querySelector('body'); | ||
const targetBtn = document.querySelector('.btn'); | ||
easyFloat.init({ | ||
container, | ||
@@ -20,5 +23,7 @@ targetBtn, | ||
fadeOutTime: 1000, | ||
}; | ||
easyFloat.init(); | ||
}); | ||
targetBtn.addEventListener('click', () => { | ||
if (!easyFloat.canClick) return; | ||
alert('do click'); | ||
}); | ||
``` | ||
@@ -25,0 +30,0 @@ |
@@ -17,2 +17,5 @@ export default class EasyFloat { | ||
this.fadeOutEnable = false; | ||
this.totalMovementX = 0; | ||
this.totalMovementY = 0; | ||
this.canClick = true; | ||
this.timer = null; | ||
@@ -119,2 +122,3 @@ this.fadeOutTimer = null; | ||
this.targetBtn.style.transition = ''; | ||
this.canClick = true; | ||
}, 300); | ||
@@ -184,3 +188,2 @@ | ||
this.targetBtn.addEventListener(startEvent, (e) => { | ||
e.preventDefault(); | ||
clearTimeout(this.timer); | ||
@@ -190,2 +193,4 @@ clearTimeout(this.fadeOutTimer); | ||
this.dragStart = true; | ||
this.totalMovementX = 0; | ||
this.totalMovementY = 0; | ||
@@ -208,2 +213,5 @@ if (startEvent === 'mousedown') { | ||
const movementY = e.movementY; | ||
this.totalMovementX += movementX; | ||
this.totalMovementY += movementY; | ||
const newLeft = this.targetBtn.offsetLeft + movementX; | ||
@@ -223,3 +231,9 @@ const newTop = this.targetBtn.offsetTop + movementY; | ||
this.initialY = touch.clientY; | ||
this.totalMovementX += movementX; | ||
this.totalMovementY += movementY; | ||
} | ||
if (Math.abs(this.totalMovementY) >= 5 || Math.abs(this.totalMovementX) >= 5) { | ||
this.canClick = false; | ||
} | ||
}); | ||
@@ -232,2 +246,6 @@ | ||
} | ||
clearListener() { | ||
window.removeEventListener('resize', this.computePositionBind); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11713
216
42