Vuetify — Parallax and Color Picker
By: John Au-Yeung
Tags: Programming, JavaScript, Software Development, Web Development, Technology

Vuetify is a popular UI framework for Vue apps.

In this article, we’ll look at how to work with the Vuetify framework.

Parallax Height

We can set the height of the parallax scrolling with the height prop.

For example, we can write:

<template>

<v-parallax dark src="https://cdn.vuetifyjs.com/images/backgrounds/vbanner.jpg" height="300">

<v-row align="center" justify="center">

<v-col class="text-center" cols="12">

<h1 class="display-1 font-weight-thin mb-4">Hello world</h1>

<h4 class="subheading">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h4>

</v-col>

</v-row>

</v-parallax>

</template> <script>

export default {

name: "HelloWorld",

data: () => ({}),

};

</script>

Color Pickers

We can add a color picker with the v-color-picker component.

The v-color-picker component uses the v-model props to control the color displayed.

For example, we can write:

<template>

<v-container>

<v-row>

<v-col cols="12" md="4">

<v-btn v-for="t in types" :key="t" class="my-4" block @click="type = t">{{ t }}</v-btn>

</v-col>

<v-col class="d-flex justify-center">

<v-color-picker v-model="color"></v-color-picker>

</v-col>

<v-col cols="12" md="4">

<v-sheet dark class="pa-4">

<pre>{{ showColor }}</pre>

</v-sheet>

</v-col>

</v-row>

</v-container>

</template> <script>

export default {

name: "HelloWorld",

data: () => ({

types: ["hex", "hexa", "rgba", "hsla", "hsva"],

type: "hex",

hex: "#FF00FF",

hexa: "#FF00FFFF",

rgba: { r: 255, g: 0, b: 255, a: 1 },

hsla: { h: 300, s: 1, l: 0.5, a: 1 },

hsva: { h: 300, s: 1, v: 1, a: 1 },

}),

computed: {

color: {

get() {

return this[this.type];

},

set(v) {

this[this.type] = v;

},

},

showColor() {

if (typeof this.color === "string") return this.color; return JSON.stringify(

Object.keys(this.color).reduce((color, key) => {

color[key] = Number(this.color[key].toFixed(2));

return color;

}, {}),

null,

2

);

},

},

};

</script>

We have the v-color picker component with the v-model to set the color state.

We set the type with the setter in the computed property.

There are different kinds of color pickers.

Picker’s Elevation

We can change the color picker’s elevation with the flat and elevation props:

<template>

<v-row justify="space-around" align="center">

<v-color-picker v-model="picker" flat></v-color-picker> <v-color-picker v-model="picker" elevation="15"></v-color-picker>

</v-row>

</template> <script>

export default {

name: "HelloWorld",

data: () => ({

picker: null,

}),

};

</script>

flat makes the color picker flat.

And elevation sets the elevation of the color picker.

Swatches

We can add the show-swatches prop to display an array of color swatches a user can pick from.

For example, we can write:

<template>

<v-row justify="space-around">

<v-color-picker class="ma-2" show-swatches></v-color-picker>

<v-color-picker class="ma-2" :swatches="swatches" show-swatches></v-color-picker>

<v-color-picker class="ma-2" show-swatches swatches-max-height="300px"></v-color-picker>

</v-row>

</template> <script>

export default {

name: "HelloWorld",

data: () => ({

swatches: null,

}),

};

</script>

We add the show-swatches prop to show the color swatch.

Conclusion

We can change the parallax container’s height and add color pickers with Vuetify.