Developing Vue Apps with the Quasar Library — Scroll Container Position and Scroll Event

John Au-Yeung
3 min readFeb 12, 2021
Photo by Antenna on Unsplash

Quasar is a popular Vue UI library for developing good looking Vue apps.

In this article, we’ll take a look at how to create Vue apps with the Quasar UI library.

Change Scroll Container Position

We can change the scroll container position programmatically with the setScrollPosition method:

<!DOCTYPE html>
<html>
<head>
<link
href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
rel="stylesheet"
type="text/css"
/>
<link
href="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.min.css"
rel="stylesheet"
type="text/css"
/>
</head>
<body class="body--dark">
<script src="https://cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.umd.min.js"></script>
<div id="q-app">
<q-layout
view="lHh Lpr lFf"
container
style="height: 100vh;"
class="shadow-2 rounded-borders"
>
<div class="q-pa-md">
<div class="row q-gutter-md q-mb-md">
<q-btn
:label="`Scroll to ${position}px`"
color="primary"
@click="scroll"
></q-btn>
<q-btn
:label="`Animate to ${position}px`"
color="primary"
@click="animateScroll"
></q-btn>
</div>
<q-scroll-area
ref="scrollArea"
style="height: 200px; max-width: 300px;"
:delay="1200"
>
<div v-for="n in 100" :key="n" class="q-py-xs">
Lorem ipsum dolor sit amet
</div>
</q-scroll-area>
</div>
</q-layout>
</div>
<script>
new Vue({
el: "#q-app",
data: {
position: 300
},
methods: {
scroll() {
this.$refs.scrollArea.setScrollPosition(this.position);
this.position = Math.floor(Math.random() * 100) * 20;
},
animateScroll() {
this.$refs.scrollArea.setScrollPosition(this.position, 300);
this.position =…

--

--