mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-22 14:09:30 -07:00
add threshold adjustment function
This commit is contained in:
@@ -37,6 +37,12 @@ footer {
|
|||||||
padding: 0 4px;
|
padding: 0 4px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.thid{
|
||||||
|
display: inline-block;
|
||||||
|
text-align: center;
|
||||||
|
width: 48px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer_imageIndex {
|
.footer_imageIndex {
|
||||||
|
|||||||
@@ -2,13 +2,27 @@ const images = document.getElementsByClassName('image')
|
|||||||
|
|
||||||
const featuredPicNum = document.body.getAttribute('featuredPicNum')
|
const featuredPicNum = document.body.getAttribute('featuredPicNum')
|
||||||
|
|
||||||
|
const thresholdNum = document.getElementsByClassName('thid')
|
||||||
|
|
||||||
|
const threshold = [0, 40, 80, 120, 160, 200]
|
||||||
|
|
||||||
|
const thresholdSensitivity = [100, 40, 18, 14, 9, 5]
|
||||||
|
|
||||||
|
let thresholdIndex = 2
|
||||||
|
|
||||||
let globalIndex = 0
|
let globalIndex = 0
|
||||||
let last = { x: 0, y: 0 }
|
let last = { x: 0, y: 0 }
|
||||||
|
|
||||||
|
// fulfill space with zero
|
||||||
function duper (num) {
|
function duper (num) {
|
||||||
return ('0000' + num).slice(-4)
|
return ('0000' + num).slice(-4)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function thresholdUpdate () {
|
||||||
|
thresholdNum.item(0).innerText = duper(threshold[thresholdIndex])
|
||||||
|
}
|
||||||
|
|
||||||
|
// footer index number display module
|
||||||
const footerIndex = document.getElementsByClassName('ftid')
|
const footerIndex = document.getElementsByClassName('ftid')
|
||||||
const numSpan = (numOne, numTwo) => {
|
const numSpan = (numOne, numTwo) => {
|
||||||
const numOneString = duper(numOne)
|
const numOneString = duper(numOne)
|
||||||
@@ -23,8 +37,26 @@ const numSpan = (numOne, numTwo) => {
|
|||||||
footerIndex.item(7).innerText = numTwoString[3]
|
footerIndex.item(7).innerText = numTwoString[3]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initialization
|
||||||
|
function init () {
|
||||||
numSpan(0, featuredPicNum)
|
numSpan(0, featuredPicNum)
|
||||||
|
thresholdUpdate()
|
||||||
|
document.getElementById('thresholdDec').addEventListener('click', function () {
|
||||||
|
if (thresholdIndex > 0) {
|
||||||
|
thresholdIndex--
|
||||||
|
thresholdUpdate()
|
||||||
|
}
|
||||||
|
}, { passive: true })
|
||||||
|
|
||||||
|
document.getElementById('thresholdInc').addEventListener('click', function () {
|
||||||
|
if (thresholdIndex < 5) {
|
||||||
|
thresholdIndex++
|
||||||
|
thresholdUpdate()
|
||||||
|
}
|
||||||
|
}, { passive: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
// let specified image show
|
||||||
const activate = (image, x, y) => {
|
const activate = (image, x, y) => {
|
||||||
image.style.left = `${x}px`
|
image.style.left = `${x}px`
|
||||||
image.style.top = `${y}px`
|
image.style.top = `${y}px`
|
||||||
@@ -35,29 +67,30 @@ const activate = (image, x, y) => {
|
|||||||
last = { x, y }
|
last = { x, y }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// absolute distance calculation
|
||||||
const distanceFromLast = (x, y) => {
|
const distanceFromLast = (x, y) => {
|
||||||
return Math.hypot(x - last.x, y - last.y)
|
return Math.hypot(x - last.x, y - last.y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// move handler
|
||||||
const handleOnMove = e => {
|
const handleOnMove = e => {
|
||||||
if (distanceFromLast(e.clientX, e.clientY) > (window.innerWidth / 20)) {
|
if (distanceFromLast(e.clientX, e.clientY) > (window.innerWidth / thresholdSensitivity[thresholdIndex])) {
|
||||||
|
// images showing array
|
||||||
const imageIndex = globalIndex % images.length
|
const imageIndex = globalIndex % images.length
|
||||||
|
|
||||||
const lead = images[imageIndex]
|
const lead = images[imageIndex]
|
||||||
const tail = images[(globalIndex - 5) % images.length]
|
const tail = images[(globalIndex - 5) % images.length]
|
||||||
|
// show top image and change index
|
||||||
activate(lead, e.clientX, e.clientY)
|
activate(lead, e.clientX, e.clientY)
|
||||||
|
|
||||||
numSpan((imageIndex + 1), featuredPicNum)
|
numSpan((imageIndex + 1), featuredPicNum)
|
||||||
|
// hide the image unused
|
||||||
console.log(imageIndex + ' /' + featuredPicNum)
|
|
||||||
|
|
||||||
if (tail) tail.dataset.status = 'inactive'
|
if (tail) tail.dataset.status = 'inactive'
|
||||||
|
// self increment
|
||||||
globalIndex++
|
globalIndex++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init()
|
||||||
|
|
||||||
window.onmousemove = e => handleOnMove(e)
|
window.onmousemove = e => handleOnMove(e)
|
||||||
|
|
||||||
window.ontouchmove = e => handleOnMove(e.touches[0])
|
window.ontouchmove = e => handleOnMove(e.touches[0])
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="footer_threshold">
|
<div class="footer_threshold">
|
||||||
Threshold:
|
Threshold:
|
||||||
<button>-</button>
|
<button id="thresholdDec">-</button>
|
||||||
<span>0080</span>
|
<span class="thid"></span>
|
||||||
<button>+</button>
|
<button id="thresholdInc">+</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="footer_imageIndex">
|
<div class="footer_imageIndex">
|
||||||
<span class="ftid"></span>
|
<span class="ftid"></span>
|
||||||
|
|||||||
Reference in New Issue
Block a user