|
| 1 | +<template> |
| 2 | + <div |
| 3 | + class="vs-blackfriday-coins"> |
| 4 | + <img |
| 5 | + v-for="coin in coins" |
| 6 | + :key="coin.id" |
| 7 | + :alt="coin.id" |
| 8 | + :src="`/images/vueschool/tech-coin-${coin.id}.png`" |
| 9 | + :class="[coin.id, coin.inverse ? inverseDirection : direction]" |
| 10 | + :style="coin.style" |
| 11 | + class="vs-blackfriday-coin"> |
| 12 | + </div> |
| 13 | +</template> |
| 14 | + |
| 15 | +<script> |
| 16 | +const coins = [ |
| 17 | + { id: 'js', inverse: true }, |
| 18 | + { id: 'ts' }, |
| 19 | + { id: 'vue', inverse: true }, |
| 20 | + { id: 'vuex', inverse: true }, |
| 21 | + { id: 'nuxt' } |
| 22 | +] |
| 23 | +
|
| 24 | +export default { |
| 25 | + data () { |
| 26 | + return { |
| 27 | + coins, |
| 28 | + xPosition: 0, |
| 29 | + direction: 'left', |
| 30 | + inverseDirection: 'right', |
| 31 | + isAnimated: false |
| 32 | + } |
| 33 | + }, |
| 34 | + mounted () { |
| 35 | + if (window.innerWidth < 1024) return |
| 36 | + this.isAnimated = true |
| 37 | + this.animationTarget = document.getElementById('vs') |
| 38 | + this.animationTarget.addEventListener('mousemove', this.animate) |
| 39 | + }, |
| 40 | + beforeDestroy () { |
| 41 | + if (!this.isAnimated) return |
| 42 | + this.animationTarget.removeEventListener('mousemove', this.animate) |
| 43 | + }, |
| 44 | + methods: { |
| 45 | + animate (e) { |
| 46 | + this.direction = e.pageX > this.xPosition ? 'right' : 'left' |
| 47 | + this.inverseDirection = this.direction === 'left' ? 'right' : 'left' |
| 48 | + this.xPosition = e.pageX |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | +</script> |
| 53 | + |
| 54 | +<style> |
| 55 | +.vs-blackfriday-coins { |
| 56 | + overflow: hidden; |
| 57 | + position: absolute; |
| 58 | + bottom: 0; |
| 59 | + right: 0; |
| 60 | + top: 0; |
| 61 | + left: 0; |
| 62 | + z-index: -1; |
| 63 | +} |
| 64 | +
|
| 65 | +.vs-blackfriday-coin { |
| 66 | + display: none; |
| 67 | +} |
| 68 | +
|
| 69 | +@media (min-width: 768px) { |
| 70 | + .vs-blackfriday-coins { |
| 71 | + background-image: url(/images/vueschool/vueschool_blackfriday_background_tablet.svg); |
| 72 | + background-position: center; |
| 73 | + background-size: cover; |
| 74 | + } |
| 75 | +} |
| 76 | +
|
| 77 | +@media (min-width: 1024px) { |
| 78 | + .vs-blackfriday-coins { |
| 79 | + background: transparent; |
| 80 | + } |
| 81 | +
|
| 82 | + #vs:hover .vs-blackfriday-coin.left { |
| 83 | + transform: translateX(-600px); |
| 84 | + transition: transform 30s linear; |
| 85 | + } |
| 86 | +
|
| 87 | + #vs:hover .vs-blackfriday-coin.right { |
| 88 | + transform: translateX(600px); |
| 89 | + transition: transform 30s linear; |
| 90 | + } |
| 91 | +
|
| 92 | + .vs-blackfriday-coin { |
| 93 | + display: inline-block; |
| 94 | + position: absolute; |
| 95 | + transition: transform 1000ms linear; |
| 96 | + transform: translateX(0); |
| 97 | + } |
| 98 | +
|
| 99 | + .vs-blackfriday-coin.js { |
| 100 | + width: 43px; |
| 101 | + top: 32px; |
| 102 | + left: calc(50% - 341px); |
| 103 | + } |
| 104 | +
|
| 105 | + .vs-blackfriday-coin.ts { |
| 106 | + top: 0; |
| 107 | + left: 0; |
| 108 | + width: 54px; |
| 109 | + left: calc(50% + 457px); |
| 110 | + } |
| 111 | +
|
| 112 | + .vs-blackfriday-coin.vue { |
| 113 | + top: 18px; |
| 114 | + width: 60px; |
| 115 | + left: calc(50% + 586px); |
| 116 | + } |
| 117 | +
|
| 118 | + .vs-blackfriday-coin.vuex { |
| 119 | + top: 23px; |
| 120 | + left: 0; |
| 121 | + width: 56px; |
| 122 | + left: calc(50% - 620px); |
| 123 | + } |
| 124 | +
|
| 125 | + .vs-blackfriday-coin.nuxt { |
| 126 | + top: 10px; |
| 127 | + width: 48px; |
| 128 | + left: calc(50% - 474px); |
| 129 | + } |
| 130 | +} |
| 131 | +</style> |
0 commit comments