I've neatly organized my links inside <li>
elements. Whenever a link is clicked, the URL of the page changes to the corresponding <div>
id element on the page.
Currently, I'm trying to figure out how to simulate the enter key press event in the makeIt()
function so that it automatically scrolls to the related <div>
element.
Take a look at my code:
<template>
<div>
<div style="margin-top: 50px;"></div>
<div style="margin-bottom: 50px;">
<ul>
<li
v-for="i in 3"
:key="i"
@click="makeIt(i)"
>
Link{{ i }}
</li>
</ul>
</div>
<div
v-for="i in 3"
:id="i"
:class="`div${i}`"
>
Div {{ i }}
</div>
</div>
</template>
<script>
export default {
methods: {
makeIt(hashbang) {
this.$router.push(`#${hashbang}`)
}
}
}
</script>
<style>
.div1 {
background-color: red;
height: 600px;
}
.div2 {
background-color: blue;
height: 500px;
}
.div3 {
background-color: yellow;
height: 500px;
}
</style>
Any suggestions on how I can achieve this objective?