Skip to content

Instantly share code, notes, and snippets.

@romainavalle
Last active June 10, 2022 09:54
Show Gist options
  • Save romainavalle/ab0bfc185e1e6ec327e16fd32a779a38 to your computer and use it in GitHub Desktop.
Save romainavalle/ab0bfc185e1e6ec327e16fd32a779a38 to your computer and use it in GitHub Desktop.
design comp
<template>
<div class="dev-design" v-show="isShown" :style="{ opacity }">
<img
v-for="(img, i) in imgsUrl"
:src="img"
:key="`img-${i}`"
v-show="currentImg === i"
/>
</div>
</template>
<script>
export default {
name: 'dev-design',
data() {
return {
isShown: false,
imgsUrl: [
'/design/1.jpg',
'/design/2.jpg',
'/design/3.jpg',
'/design/4.jpg',
'/design/5.jpg',
'/design/6.jpg'
],
currentImg: 0,
opacity: 0.5
}
},
methods: {},
mounted() {
window.addEventListener('keydown', (e) => {
if (e.key === 'ArrowUp') {
this.opacity += 0.1
if (this.opacity > 1) this.opacity = 1
}
if (e.key === 'ArrowDown') {
this.opacity -= 0.1
if (this.opacity < 0) this.opacity = 0
}
if (e.key === 'ArrowRight') {
this.currentImg++
if (this.currentImg > this.imgsUrl.length - 1) this.currentImg = 0
}
if (e.key === 'ArrowLeft') {
this.currentImg--
if (this.currentImg < 0) this.currentImg = this.imgsUrl.length - 1
}
if (e.key === 'd') {
this.isShown = !this.isShown
}
})
}
}
</script>
<style lang="scss">
.dev-design {
position: fixed;
top: 0;
left: 0;
pointer-events: none;
width: 100%;
z-index: 100;
img {
position: absolute;
top: 0;
left: 0;
width: 100%;
display: block;
}
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment