|
@@ -0,0 +1,167 @@
|
|
|
+<template>
|
|
|
+ <div class="compare-pic" ref="compare-pic">
|
|
|
+ <img :class="`img-item img-item-0`" :src="imgs[0]" />
|
|
|
+ <div class="beetween-ctrls" @mousedown="handleMousedown" :style="{left: `${newPosition}%`}">
|
|
|
+ <div class="line"></div>
|
|
|
+ <div class="circle-ctrls">
|
|
|
+ <div class="animation-circle"></div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div :class="`img-item img-item-1`" :style="{'background-image': `url(${imgs[1]})`, width: `${100 - newPosition}%`}"></div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+export default {
|
|
|
+ props: {
|
|
|
+ imgs: Array
|
|
|
+ },
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ newPosition: 50,
|
|
|
+ maxWidth: 0,
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ handleMousedown (event) {
|
|
|
+ this.onDragStart(event)
|
|
|
+ window.addEventListener('mousemove', this.onDragging)
|
|
|
+ window.addEventListener('touchmove', this.onDragging)
|
|
|
+ window.addEventListener('mouseup', this.onDragEnd)
|
|
|
+ window.addEventListener('touchend', this.onDragEnd)
|
|
|
+ window.addEventListener('contextmenu', this.onDragEnd)
|
|
|
+ },
|
|
|
+ onDragEnd () {
|
|
|
+ window.removeEventListener('mousemove', this.onDragging)
|
|
|
+ window.removeEventListener('touchmove', this.onDragging)
|
|
|
+ window.removeEventListener('mouseup', this.onDragEnd)
|
|
|
+ window.removeEventListener('touchend', this.onDragEnd)
|
|
|
+ window.removeEventListener('contextmenu', this.onDragEnd)
|
|
|
+ },
|
|
|
+ onDragStart(event) {
|
|
|
+ this.dragging = true;
|
|
|
+ this.isClick = true;
|
|
|
+ const rect = this.$refs['compare-pic'].getClientRects()
|
|
|
+ this.maxWidth = rect[0].width
|
|
|
+ if (event.type === 'touchstart') {
|
|
|
+ event.clientY = event.touches[0].clientY;
|
|
|
+ event.clientX = event.touches[0].clientX;
|
|
|
+ }
|
|
|
+ this.startX = event.clientX
|
|
|
+ },
|
|
|
+ onDragging (event) {
|
|
|
+ this.isClick = false;
|
|
|
+ // this.displayTooltip();
|
|
|
+ let diff = 0;
|
|
|
+ if (event.type === 'touchmove') {
|
|
|
+ event.clientY = event.touches[0].clientY;
|
|
|
+ event.clientX = event.touches[0].clientX;
|
|
|
+ }
|
|
|
+ this.currentX = event.clientX;
|
|
|
+
|
|
|
+ diff = (this.currentX - this.startX) / this.maxWidth * 100
|
|
|
+ this.startX = this.currentX
|
|
|
+ this.setPosition(this.newPosition + diff);
|
|
|
+ },
|
|
|
+ setPosition(newPosition) {
|
|
|
+ if (newPosition === null || isNaN(newPosition)) return;
|
|
|
+ if (newPosition < 0) {
|
|
|
+ newPosition = 0;
|
|
|
+ } else if (newPosition > 100) {
|
|
|
+ newPosition = 100;
|
|
|
+ }
|
|
|
+ this.newPosition = newPosition
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped>
|
|
|
+.compare-pic {
|
|
|
+ position: relative;
|
|
|
+ height: 100%;
|
|
|
+ width: 100%;
|
|
|
+}
|
|
|
+.img-item {
|
|
|
+ width: 1276px;
|
|
|
+ height: 673px;
|
|
|
+ background-size: cover;
|
|
|
+ background-repeat: no-repeat;
|
|
|
+ background-position: center center;
|
|
|
+ user-select: none;
|
|
|
+ &-1 {
|
|
|
+ position: absolute;
|
|
|
+ right: 0;
|
|
|
+ top: 0;
|
|
|
+ z-index: 1;
|
|
|
+ width: 50%;
|
|
|
+ background-position: top right;
|
|
|
+ }
|
|
|
+}
|
|
|
+.beetween-ctrls {
|
|
|
+ position: absolute;
|
|
|
+ height: 100%;
|
|
|
+ top: 0;
|
|
|
+ left: 50%;
|
|
|
+ transform: translate(-50%, 0);
|
|
|
+ z-index: 2;
|
|
|
+ .line {
|
|
|
+ height: 100%;
|
|
|
+ width: 3px;
|
|
|
+ background: #fff;
|
|
|
+ }
|
|
|
+}
|
|
|
+.circle-ctrls {
|
|
|
+ width: 104px;
|
|
|
+ height: 104px;
|
|
|
+ cursor: pointer;
|
|
|
+ border-radius: 50%;
|
|
|
+ background: rgba(255, 255, 255, 0.4);
|
|
|
+ position: absolute;
|
|
|
+ top: 50%;
|
|
|
+ left: 50%;
|
|
|
+ margin: -52px 0 0 -52px;
|
|
|
+ user-select: none;
|
|
|
+ &::before, &::after {
|
|
|
+ content: '';
|
|
|
+ position: absolute;
|
|
|
+ top: 50%;
|
|
|
+ transform: translate(0, -50%);
|
|
|
+ background: url(~@/assets/images/core-products/sxz/left-arrow.png) no-repeat center center;
|
|
|
+ width: 16px;
|
|
|
+ height: 30px;
|
|
|
+ }
|
|
|
+ &::before {
|
|
|
+ left: 21px;
|
|
|
+ }
|
|
|
+ &::after {
|
|
|
+ right: 21px;
|
|
|
+ background-image: url(~@/assets/images/core-products/sxz/right-arrow.png);
|
|
|
+ }
|
|
|
+ .animation-circle {
|
|
|
+ width: 104px;
|
|
|
+ height: 104px;
|
|
|
+ border: 2px solid rgba(255, 255, 255, 0.4);
|
|
|
+ animation: mymove-data 1s infinite;
|
|
|
+ border-radius: 50%;
|
|
|
+ position: absolute;
|
|
|
+ top: 50%;
|
|
|
+ left: 50%;
|
|
|
+ transform: translate(-50%, -50%);
|
|
|
+ }
|
|
|
+}
|
|
|
+@keyframes mymove-data {
|
|
|
+ from {
|
|
|
+ width: 104px;
|
|
|
+ height: 104px;
|
|
|
+ opacity: 0.4
|
|
|
+ }
|
|
|
+
|
|
|
+ to {
|
|
|
+ width: 150px;
|
|
|
+ height: 150px;
|
|
|
+ // transform: translateX(-20px) translateY(-20px);
|
|
|
+ opacity: 0
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|