Skip to content

Instantly share code, notes, and snippets.

@atomjoy
Last active March 22, 2025 10:37
Show Gist options
  • Save atomjoy/5efb3d851bca7af6f60dbdd4d0c264ec to your computer and use it in GitHub Desktop.
Save atomjoy/5efb3d851bca7af6f60dbdd4d0c264ec to your computer and use it in GitHub Desktop.
Vue 3 css v-bind attributes, color and background image url (background-attachment fixed).
<script setup>
import { onBeforeMount } from 'vue';
let props = defineProps({
image: { type: String, default: '/default/default.webp' },
});
onBeforeMount(() => {
const img = new Image();
img.src = props.image;
});
</script>
<template>
<div class="page_banner fixed_bg" v-bind:style="{ backgroundImage: 'url(' + props.image + ')' }">
<slot />
</div>
</template>
<style scoped>
.fixed_bg {
float: left;
width: 100%;
height: 250px;
background-size: cover;
background-position: center;
background-attachment: fixed;
}
</style>
<script setup>
let props = defineProps({
color: { type: String, default: '#0099ff' },
text: { type: String, default: 'Colored Text' },
size: { type: String, default: '25px' },
});
</script>
<template>
<span class="colored_text">{{ text }}</span>
</template>
<style scoped>
.attribute {
--color: v-bind(props.color);
}
.colored_text {
margin-right: 20px;
color: v-bind('props.color');
font-size: v-bind('props.size');
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment