const getByIdMoveArea = id => {
const oWrapper = document.querySelector('.list-call-wrapper .phone-wrapper')
const childNodes = [...oWrapper.childNodes]
const fId = id || this.fixedId
const item = childNodes.find(e => e.id === fId)
const fBottom = oWrapper.clientHeight + oWrapper.scrollTop - item.offsetHeight
const fTop = oWrapper.scrollTop
const target = item.offsetTop
if (target >= fTop && target <= fBottom) return
clearInterval(oWrapper.timer)
oWrapper.oldScrollTop = null
if (target < fTop) {
oWrapper.timer = setInterval(() => startMove(oWrapper.scrollTop, item), 10)
} else {
const lastItemTop = childNodes[childNodes.length - 1].offsetTop
const isArea = lastItemTop - item.offsetTop >= oWrapper.clientHeight
oWrapper.timer = setInterval(() => {
const cptItem = isArea ? item : findAreaFirstItem(childNodes, oWrapper)
startMove(oWrapper.scrollTop, cptItem)
}, 10)
}
function startMove(target, item) {
let speed = (item.offsetTop - target) / 8
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed)
if (target === item.offsetTop || oWrapper.scrollTop === oWrapper.oldScrollTop) {
clearInterval(oWrapper.timer)
} else {
oWrapper.oldScrollTop = oWrapper.scrollTop
oWrapper.scrollTop = oWrapper.scrollTop + speed
}
}
function findAreaFirstItem(childNodes, oWrapper) {
let item = null
for (let i = childNodes.length - 1; i >= 0; i--) {
if (childNodes[i].offsetTop <= oWrapper.scrollHeight - oWrapper.clientHeight) {
item = childNodes[i + 1]
break
}
}
return item
}
}