I'm implementing button which will on click vertically scroll down for one team member. So far I have managed that one click scrolls down for one team member, but the code breaks when user manually scrolls back to top.
Here is working JSFiddle
My code
<main class="team container">
<div v-for='(element, index) in members' :id="element.specialId" class="team__member" v-show="activeIndex === index || widthSmall">
<div class="team__member__bio">
<div class="team__member__name">{{element.name}}</div>
</div>
</div>
<a class="scroll-more scroll-team" v-show="widthSmall" @click="move($event)" style="cursor: pointer;">
<span></span>{{ $t('scroll') }}
</a>
</main>
export default {
name: "Team",
data() {
return {
members: [
{
name: "Bojan Dovrtel",
specialId: 'bojan-div'
},
{
name: "Klemen Razinger",
specialId: 'kelemen-div'
},
{
name: "Davor Pečnik",
specialId: 'davor-div'
},
{
name: "Maja Katalinič",
specialId: 'maja-div'
},
{
name: "Petra Vovk",
specialId: 'petra-div'
}
],
secs: document.getElementsByClassName('team__member'),
currentSection: 0,
}
},
methods: {
move(e) {
if (this.currentSection < this.secs.length) {
if (this.currentSection === 3) {
this.widthSmall = false;
}
window.scroll({
top: this.secs[++this.currentSection].offsetTop,
left: 0,
behavior: 'smooth'
});
} else if (this.currentSection > 0) {
window.scroll({
top: this.secs[--this.currentSection].offsetTop,
left: 0,
behavior: 'smooth'
});
}
}
}
};
How can I detect that users have scrolled up and change the value of current section? If you have any additional informations, please let me know and I will provide. Thank you