Answer the question
In order to leave comments, you need to log in
Why does smooth scrolling disappear when adding a menu close?
<div class="header-flex__item" @click="menuShow=!menuShow">Меню</div>
<transition name="fade">
<div class="header-menu" v-if="menuShow">
<nav>
<ul>
<li v-for="menuLink in menuLinks" :key="menuLink.name">
<a :href="menuLink.link" @click="menuShow=!menuShow,goToBlock">{{menuLink.name}}</a>
</li>
</ul>
</nav>
</div>
</transition>
data() {
return {
menuShow: false,
menuLinks: [
{
name: "Особенности",
link: "#features",
},
{
name: "О компании",
link: "#about",
},
{
name: "Сравнение",
link: "#comparison",
},
{
name: "Каталог",
link: "#catalog",
},
{
name: "Галерея",
link: "#gallery",
},
{
name: "Бани внутри",
link: "#inside",
},
{
name: "Этапы",
link: "#stages",
},
{
name: "Контакты",
link: "#contacts",
},
],
};
},
methods: {
goToBlock: function (event) {
event.preventDefault();
const link = event.target.getAttribute("href");
document
.querySelector(link)
.scrollIntoView({ behavior: "smooth", block: "start" });
},
},
Answer the question
In order to leave comments, you need to log in
@click="menuShow=!menuShow,goToBlock"
@click="menuShow = !menuShow, goToBlock($event)"
methods: {
goToBlock(selector) {
document.querySelector(selector).scrollIntoView({
behavior: 'smooth',
});
},
onMenuItemClick(e) {
this.menuShow = false;
this.goToBlock(e.target.getAttribute('href'));
},
},
@click.prevent="onMenuItemClick"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question