Skip to content

Commit

Permalink
fix(projects): make preview animation trigger on the whole card width
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed Feb 5, 2021
1 parent 11c7813 commit add7b75
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/components/flipable-card/FlipableCard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: transform 1s;
transition: transform 0.5s;

&__face {
position: absolute;
Expand Down
26 changes: 12 additions & 14 deletions src/components/project-model-preview/ProjectModelPreview.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<template>
<div class="project-model-preview">
<div
class="project-model-preview__wrapper"
ref="previewWrapper"
@mousemove="translate"
>
<div class="project-model-preview" ref="container" @mousemove="translate">
<div class="project-model-preview__wrapper" ref="viewport">
<img
:src="image || '/static/default-model-preview.png'"
:style="{ transform: `translateX(-${translation}px)` }"
Expand All @@ -28,18 +24,19 @@ export default {
const { fetchProjectPreviewImage } = useProjects();
const nbSlices = 15;
const previewWrapper = ref(null);
const container = ref(null);
const viewport = ref(null);
const translation = ref(0);
const translate = event => {
if (previewWrapper.value) {
const wrapper = previewWrapper.value.getBoundingClientRect();
if (container.value && viewport.value) {
const c = container.value.getBoundingClientRect();
const v = viewport.value.getBoundingClientRect();
let index = Math.abs(
Math.ceil(
nbSlices * (1 - (event.clientX - wrapper.x) / wrapper.width)
)
Math.ceil(nbSlices * (1 - (event.clientX - c.x) / c.width))
);
index = Math.min(index, nbSlices);
translation.value = (index - 1) * wrapper.width;
translation.value = (index - 1) * v.width;
}
};
Expand All @@ -50,9 +47,10 @@ export default {
return {
// References
container,
image,
previewWrapper,
translation,
viewport,
// Methods
translate
};
Expand Down

0 comments on commit add7b75

Please sign in to comment.