vue overflow中实现键盘上下键滚动
2024年1月25日小于 1 分钟约 228 字
vue2写法
this.$refs['获取元素'].$el.scrollLeft = 300方法二:
<ul class="branchChoiceData" ref = "list">
<li v-for="(item, index) in infoOp"
:key="item.remoteKey"
:tabindex="index"
:class="[focus.active === index ? 'focus' : '']">
...
<!-- more -->
</ul>let focus = reactive({
active: 0
})
let list = ref(null)
let branchLength = ref(null)
function _handleUp() {
focus.active = (focus.active - 1 + branchLength._value) % branchLength._value
if ((branchLength._value > 4 && focus.active >= 3)) {
list._value.scrollTop = (focus.active !== branchLength._value - 1) ? list._value.scrollTop - 58 : 800
}
}
function _handleDown() {
focus.active = (focus.active + 1) % branchLength._value
if ((branchLength._value > 4 && focus.active > 3) || focus.active === 0) {
list._value.scrollTop = focus.active !== 0 ? list._value.scrollTop + 58 : 0
}
} .branchChoiceData {
width: 100%;
height: 240px;
background: rgb(114, 118, 120);
border-width: 0px 40px 6px 6px;
border: solid rgb(15, 15, 19);
overflow-x: auto;
overflow-y: scroll;
> li {
width: 100%;
height: 58px;
line-height: 58px;
list-style: none;
.listItem {
display: flex;
}
}
.divider {
width: 100%;
margin: 0;
border: 1px solid rgb(15, 15, 19);
size: 5px;
}
.focus {
background: rgb(142, 154, 84);
}
}