Skip to content

Commit

Permalink
Use <transition> for navigation (#22)
Browse files Browse the repository at this point in the history
Here I also removed the background image

Closes #22
  • Loading branch information
kytta committed Jan 8, 2020
1 parent 10b1ae9 commit 864b6b6
Showing 1 changed file with 38 additions and 52 deletions.
90 changes: 38 additions & 52 deletions src/tinybox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,17 @@
@touchmove="swipe"
@touchend="swipeEnd"
>
<div
:style="`background:url('${switchFrom.src}')`"
class="tinybox__content__current"
>
<transition :name="`slide-${slide}`">
<img
:class="transitionClass"
:key="current.src"
:src="current.src"
:alt="current.alt || ''"

class="tinybox__content__current__image"

@click.stop="next"

@animationend="transitionClass = ''"
>
</div>
</transition>
<div
v-if="hasPrev"

Expand Down Expand Up @@ -128,7 +123,7 @@ export default {
swipeX: null,
switchFrom: null,
transitionClass: '',
slide: 'rtl',
};
},
computed: {
Expand Down Expand Up @@ -181,7 +176,6 @@ export default {
goto(index) {
this.switchFrom = this.current;
let transition = '';
if (index !== null) {
let newIndex = index;
Expand All @@ -193,11 +187,10 @@ export default {
}
if (this.cIndex != null && this.cIndex !== newIndex) {
transition = this.cIndex < newIndex ? 'tinybox__content__current__image--rtl' : 'tinybox__content__current__image--ltr';
this.slide = this.cIndex < newIndex ? 'rtl' : 'ltr';
}
}
this.transitionClass = transition;
this.cIndex = index;
},
Expand Down Expand Up @@ -267,12 +260,6 @@ export default {
vertical-align: middle;
}
.tinybox__content__current {
background-size: cover;
display: inline-block;
vertical-align: middle;
}
.tinybox__content__current__image {
border: none;
cursor: pointer;
Expand All @@ -285,40 +272,7 @@ export default {
position: relative;
vertical-align: middle;
width: auto;
animation: 300ms ease 1 normal;
}
.tinybox__content__current__image--ltr {
animation-name: ltr;
}
.tinybox__content__current__image--rtl {
animation-name: rtl;
}
@keyframes ltr {
from {
opacity: 0;
transform: translateX(-80px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
@keyframes rtl {
from {
opacity: 0;
transform: translateX(80px);
}
to {
opacity: 1;
transform: translateX(0);
}
background-color: #222;
}
.tinybox__content__control {
Expand Down Expand Up @@ -406,4 +360,36 @@ export default {
.fade-enter, .fade-leave-active {
opacity: 0;
}
.slide-ltr-enter-active,
.slide-rtl-enter-active {
animation: 300ms ease 1 normal;
}
.slide-rtl-enter-active {
animation-name: rtl;
}
.slide-ltr-enter-active {
animation-name: ltr;
}
@keyframes ltr {
from {
opacity: 0;
transform: translateX(-80px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
@keyframes rtl {
from {
opacity: 0;
transform: translateX(80px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
</style>

0 comments on commit 864b6b6

Please sign in to comment.