效果图
不废话,直接上源码!
组件直接用
<template>
<view
class="img-comparison-container"
:style="'width:' + width + 'rpx;height:' + height + 'rpx'"
>
<view class="before-image" :style="'width:' + x + 'rpx'">
<view :style="'width:' + width + 'rpx;height:' + height + 'rpx'">
<image
:src="beforeImageUrl"
class="images"
mode="aspectFill"
data-type="before"
@tap="previewImage"
/>
</view>
<view v-if="beforeText" class="before-text">
{
{
beforeText }}
</view>
</view>
<view class="after-image">
<view :style="'width:' + width + 'rpx;height:' + height + 'rpx'">
<image
:src="afterImageUrl"
class="images"
mode="aspectFill"
data-type="after"
@tap="previewImage"
/>
</view>
<view v-if="afterText" class="after-text">
{
{
afterText }}
</view>
</view>
<view
class="slider-bar"
:style="'left:' + x + 'rpx'"
@touchmove="handleTouchMove"
@touchstart="handleTouchStart"
@touchend="handleTouchEnd"
>
<view class="slider-button"></view>
</view>
</view>
</template>
<script>
export default {
props: