mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-21 05:29:31 -07:00
now img index calculation is a standalone function in utils.ts
This commit is contained in:
@@ -5,7 +5,8 @@ import {
|
|||||||
layersPosSet,
|
layersPosSet,
|
||||||
center,
|
center,
|
||||||
type position,
|
type position,
|
||||||
createImgElement
|
createImgElement,
|
||||||
|
calcImageIndex
|
||||||
} from './utils'
|
} from './utils'
|
||||||
import { thresholdSensitivityArray, thresholdIndex } from './thresholdCtl'
|
import { thresholdSensitivityArray, thresholdIndex } from './thresholdCtl'
|
||||||
import { imgIndexSpanUpdate } from './indexDisp'
|
import { imgIndexSpanUpdate } from './indexDisp'
|
||||||
@@ -27,7 +28,7 @@ export const posArray: string[][] = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
// global index for "activated"
|
// global index for "activated"
|
||||||
let globalIndex: number = 0
|
export let globalIndex: number = 0
|
||||||
|
|
||||||
// last position set as "activated"
|
// last position set as "activated"
|
||||||
let last: position = { x: 0, y: 0 }
|
let last: position = { x: 0, y: 0 }
|
||||||
@@ -73,7 +74,7 @@ export const handleOnMove = (e: MouseEvent): void => {
|
|||||||
window.innerWidth / thresholdSensitivityArray[thresholdIndex]
|
window.innerWidth / thresholdSensitivityArray[thresholdIndex]
|
||||||
) {
|
) {
|
||||||
// calculate the actual index
|
// calculate the actual index
|
||||||
const imageIndex = globalIndex % imagesArrayLen
|
const imageIndex = calcImageIndex(globalIndex, imagesArrayLen)
|
||||||
// show top image and change index
|
// show top image and change index
|
||||||
activate(imageIndex, e.clientX, e.clientY)
|
activate(imageIndex, e.clientX, e.clientY)
|
||||||
imgIndexSpanUpdate(imageIndex + 1, imagesArrayLen)
|
imgIndexSpanUpdate(imageIndex + 1, imagesArrayLen)
|
||||||
|
|||||||
@@ -88,3 +88,11 @@ export function createImgElement(input: ImageData): HTMLImageElement {
|
|||||||
img.setAttribute('width', input.imgW)
|
img.setAttribute('width', input.imgW)
|
||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function calcImageIndex(index: number, imgCounts: number): number {
|
||||||
|
if (index >= 0) {
|
||||||
|
return index % imgCounts
|
||||||
|
} else {
|
||||||
|
return imgCounts + (index % imgCounts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user