I’m trying to make 2 buttons for a scroll left and scroll right while working on a Netflix copy, as you can imagine i’m just learning. I’m working on my project with VueJs, i made my btns work but they only work on the movie list while the rest of the btn does nothing, i’m missing something for sure but i still didn’t find a solution:
<Template>
<!-- this is our film container -->
<div id="movieCards" class="container pt-5 pb-5" v-if="store.movie.length > 0">
<div>
<h2>
Film
</h2>
</div>
<div ref="movieScrollContainer" class="dflex">
<div class="ls-col" v-for="movie in store.movie" :key="movie.id">
<CardComponent :img="store.ImageUrl + movie.poster_path" :name="movie.title" :originalName="movie.original_title" :language="movie.original_language" :vote="movie.vote_average" :overview="movie.overview"/>
</div>
</div>
<div class="d-flex justify-content-between ">
<button id="scrollLeftMovie" @click="scroll(-600, 'movieScrollContainer')">
scroll left
</button>
<button id="scrollRightMovie" @click="scroll(600, 'movieScrollContainer')">
scroll right
</button>
</div>
</div>
<!-- this is our tvseries container -->
<div ref="tvScrollContainer" id="tvCards" class="container pt-5 pb-5" v-if="store.movie.length > 0">
<div>
<h2>
Serie TV
</h2>
</div>
<div class="dflex">
<div class="ls-col" v-for="series in store.tv" :key="series.id">
<CardComponent :img="store.ImageUrl + series.poster_path" :name="series.name" :originalName="series.original_name" :language="series.original_language" :vote="series.vote_average" :overview="series.overview"/>
</div>
</div>
<div class="d-flex justify-content-between">
<button id="scrollLeftTv" @click="scroll(-600, 'tvScrollContainer')">
scroll left
</button>
<button id="scrollRightTv" @click="scroll(600, 'tvScrollContainer')">
scroll right
</button>
</div>
</div>
</Template>
i triyed to give a 2nd parameter to the function but it seems i’m doing it wrong. Function here:
<script>
import { store } from '../store';
import CardComponent from './CardComponent.vue';
export default {
name: 'CardList',
components: {
CardComponent
},
data() {
return {
store
}
},
methods: {
scroll(distance, id) {
this.$refs[id].scrollBy({
left: distance,
behavior: 'smooth'
})
}
}
}
</script>
Can someone help me understand what is missing?