mirror of
https://github.com/201206030/novel-front-web.git
synced 2025-04-27 07:50:50 +00:00
feat: 内容页左右箭头键盘监听
This commit is contained in:
parent
364c4fd489
commit
f8fe50654c
@ -13,7 +13,8 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a
|
||||||
class="ico_catalog" @click="chapterList(data.chapterInfo.bookId)"
|
class="ico_catalog"
|
||||||
|
@click="chapterList(data.chapterInfo.bookId)"
|
||||||
href="javascript:void(0)"
|
href="javascript:void(0)"
|
||||||
title="目录"
|
title="目录"
|
||||||
>
|
>
|
||||||
@ -147,7 +148,7 @@
|
|||||||
style="background-color: rgba(255, 255, 255, 0.45)"
|
style="background-color: rgba(255, 255, 255, 0.45)"
|
||||||
class="dir"
|
class="dir"
|
||||||
@click="chapterList(data.chapterInfo.bookId)"
|
@click="chapterList(data.chapterInfo.bookId)"
|
||||||
href="javascript:void(0)"
|
href="javascript:void(0)"
|
||||||
>目录</a
|
>目录</a
|
||||||
>
|
>
|
||||||
<a
|
<a
|
||||||
@ -298,7 +299,8 @@ export default {
|
|||||||
imgBaseUrl: process.env.VUE_APP_BASE_IMG_URL,
|
imgBaseUrl: process.env.VUE_APP_BASE_IMG_URL,
|
||||||
});
|
});
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
init(route.params.chapterId);
|
init(route.params.chapterId)
|
||||||
|
keyDown()
|
||||||
});
|
});
|
||||||
|
|
||||||
const bookDetail = (bookId) => {
|
const bookDetail = (bookId) => {
|
||||||
@ -335,6 +337,25 @@ export default {
|
|||||||
state.data = data;
|
state.data = data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 监听键盘
|
||||||
|
const keyDown = () => {
|
||||||
|
document.onkeydown = (e) => {
|
||||||
|
//事件对象兼容
|
||||||
|
let e1 = e || event || window.event || arguments.callee.caller.arguments[0]
|
||||||
|
//键盘按键判断:左箭头-37;上箭头-38;右箭头-39;下箭头-40
|
||||||
|
const bookId = state.data.chapterInfo.bookId;
|
||||||
|
//左
|
||||||
|
if (e1 && e1.keyCode == 37) {
|
||||||
|
// 按下左箭头
|
||||||
|
preChapter(bookId);
|
||||||
|
} else if (e1 && e1.keyCode == 39) {
|
||||||
|
// 按下右箭头
|
||||||
|
nextChapter(bookId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...toRefs(state),
|
...toRefs(state),
|
||||||
bookDetail,
|
bookDetail,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user