Skip to content

Commit

Permalink
Fix if the cursor is pulled to the left it goes out of the box
Browse files Browse the repository at this point in the history
  • Loading branch information
j2only committed Mar 4, 2024
1 parent 10b1e87 commit 8d404f9
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 98 deletions.
21 changes: 14 additions & 7 deletions lib/SlideUnlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,16 @@ export default defineComponent({
const slideMoving = (e: unknown) => {
if (Slider.CanMove && !Slider.IsComplete) {
let pageX = Slider.StartPositionWindow
if (window.TouchEvent && e instanceof TouchEvent && e.touches)
Slider.HandlerPosition = (e.touches[0].pageX) - Slider.StartPositionWindow
pageX = e.touches[0].pageX
else if (e instanceof MouseEvent)
Slider.HandlerPosition = (e.pageX) - Slider.StartPositionWindow
pageX = e.pageX
if (pageX < Slider.StartPositionWindow)
return
else
Slider.HandlerPosition = pageX - Slider.StartPositionWindow
if (Slider.HandlerPosition > 0 && Slider.HandlerPosition <= (sliderWidth.value - props.height)) {
Slider.ProgressWidth = (Slider.HandlerPosition + props.height / 2)
Expand All @@ -183,13 +188,15 @@ export default defineComponent({
const slideFinish = (e: unknown) => {
if (Slider.CanMove && !Slider.IsComplete) {
let pageX = Slider.StartPositionWindow
if (window.TouchEvent && e instanceof TouchEvent && e.touches)
Slider.HandlerPosition = (e.changedTouches[0].pageX) - Slider.StartPositionWindow
pageX = e.changedTouches[0].pageX
else if (e instanceof MouseEvent)
Slider.HandlerPosition = (e.pageX) - Slider.StartPositionWindow
pageX = e.pageX
if (Slider.HandlerPosition < (sliderWidth.value - props.height)) {
if (pageX < Slider.StartPositionWindow)
return
else if (Slider.HandlerPosition < (sliderWidth.value - props.height)) {
ease({
startValue: Slider.HandlerPosition,
endValue: 0,
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@j2only/slide-unlock",
"version": "0.5.1",
"version": "0.5.2",
"type": "module",
"description": "Vue.js slide to unlock component. Protect users from accidental clicks or protect your web app from bot attack.",
"author": "Anton Zolotov <antonzolotov@outlook.com>",
Expand Down Expand Up @@ -37,18 +37,18 @@
"dependencies": {
"easy-ease": "^1.0.9",
"lodash.debounce": "^4.0.8",
"vue": "^3.4.20"
"vue": "^3.4.21"
},
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.23.9",
"@babel/plugin-transform-runtime": "^7.24.0",
"@babel/preset-typescript": "^7.23.3",
"@cypress/code-coverage": "^3.12.24",
"@cypress/code-coverage": "^3.12.26",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@stylistic/stylelint-plugin": "^2.1.0",
"@types/babel__plugin-transform-runtime": "^7.9.5",
"@types/eslint": "^8.56.3",
"@types/eslint": "^8.56.5",
"@types/lodash.debounce": "^4.0.9",
"@types/node": "^20.11.20",
"@types/node": "^20.11.24",
"@vitejs/plugin-vue": "^5.0.4",
"@vitest/coverage-istanbul": "^1.3.1",
"@vue/eslint-config-standard": "^8.0.1",
Expand Down Expand Up @@ -111,4 +111,4 @@
"lib": "lib",
"test": "tests"
}
}
}
Loading

0 comments on commit 8d404f9

Please sign in to comment.