在春风动力的官网里看到了这个效果,然后自己写了一个
效果:
使用:

<he-contrast width="600"><template #left><img src="@/assets/img/VFX2-before.jpg" class="images" /></template><template #right><img src="@/assets/img/VFX2-after.jpg" class="images" /></template>
</he-contrast>

组件封装:

<template><divclass="PictureComparison":style="'width:' + width + 'px;height:' + height + 'px'"><div class="before-image" :style="'width:' + x + 'px'" @click.stop="goLeft"><div :style="'width:' + width + 'px;height:' + height + 'px'"><slot name="left"></slot></div></div><div class="after-image" @click.stop="goRight"><div :style="'width:' + width + 'px;height:' + height + 'px'"><slot name="right"></slot></div></div><divclass="divider-bar":style="'left:' + x + 'px'"@mousedown.prevent="onmouseDown()"></div></div>
</template><script>
import { reactive, toRefs } from "vue";
export default {props: {width: { type: String, default: "500" },height: { type: String, default: "300" },},setup(props) {const data = reactive({isDown: false, //鼠标是否正按住moveX: 0, //鼠标移动的位置x: props.width / 2, //设置位置});const onmouseDown = () => {data.isDown = true;data.x = event.target.offsetLeft;var disX = event.clientX - event.target.offsetLeft;document.onmousemove = function (event) {if (data.isDown == false) {return;}data.x = event.clientX - disX;if (data.x >= props.width) {data.x = props.width;} else if (data.x <= 0) {data.x = 0;}};document.onmouseup = function () {data.isDown = false;document.onmousemove = document.onmouseup = null;return false;};};const goLeft = () => {data.x = 0;};const goRight = () => {data.x = props.width;};return {...toRefs(data),onmouseDown,goLeft,goRight,};},
};
</script><style lang="less" scoped>
.PictureComparison {position: relative;display: inline-block;margin: 0 auto;min-height: 273px;margin-bottom: 40px;overflow: hidden;.before-image {position: absolute;top: 0;left: 0;z-index: 1;width: 50%;overflow: hidden;}.after-image {position: absolute;top: 0;left: 0;z-index: 0;}.divider-bar {cursor: move;position: absolute;width: 1px;left: 50%;top: 0px;background: white;height: 100%;display: block;z-index: 2;box-shadow: 0 0 10px 1px rgba(0, 0, 0, 0.4);&::after {content: "<|>";position: absolute;color: #ccc;text-align: center;line-height: 18px;width: 40px;height: 20px;background: #fff;border-radius: 10px;top: 50%;left: 50%;transform: translate(-50%, -50%);}}
}
</style>

最后推荐一个前端开发好用的导航网站:www.888i8.cn

vue3图片对比组件相关推荐

  1. Vue3+ Vue-cli (2) 组件篇

    目录 一.全局组件定义和复用性讲解 二.Vue3中的局部组件 三.父子组件的静态和动态传值 四.组件传值时的校验操作 五.组件中重要机制 - 单项数据流 六.Non-props使用技巧 七.组件中通过 ...

  2. v-viewer:vue3图片查看器

    v-viewer:一个方便易用的vue3 图片查看器 v-viewer中文文档 一.安装 1.npm/yarn 安装 npm install v-viewer@next or yarn add vie ...

  3. vue3.0 父组件调用子组件方法及获取子组件的值

    vue3.0 父组件调用子组件方法及获取子组件的值 通过对比2.0的获取及调用方式这里我们也可以借鉴2.0中的this.$refs去获取3.0和2.0的refs获取的方式有点大同小异,但是思路还是一样 ...

  4. 七十三、Vue项目城市详细页的动态路由,Banner布局和公用图片画廊组件拆分

    2020/11/04. 周四.今天又是奋斗的一天. @Author:Runsen 写在前面:我是「Runsen」,热爱技术.热爱开源.热爱编程.技术是开源的.知识是共享的.大四弃算法转前端,需要每天的 ...

  5. Vue性能优化:图片与组件,如何实现按需加载?

    Vue性能优化:图片与组件,如何实现按需加载? 前沿:按需加载是性能优化其中的一个环节,可以是图片的按需加载,也就是lazyload来实现按需加载的场景,也可以是组件库的引入,只需部分组件的使用而无需 ...

  6. python找图片不同_用openCV和Python 实现图片对比,并标识出不同点的方式

    最近项目中需要实现两组图片对比,并能将两者的区别标识出来. 在网上搜索一大堆找到一篇大神的文章,最终实现该功能,在这里记录下: 想要实现此demo,首先我们得确保电脑上已安装 openCV 和 Pyt ...

  7. 微信小程序|开发实战篇之九-image-picker图片选择器组件及其子组件

    开发实战篇之九 前言 1.grid格子组件 1.1 grid骨架文件wxml 1.2 grid的js文件分析 1.3 grid-item的wxml文件分析 1.4 grid-item的wxss文件分析 ...

  8. python图像对比_python+PIL实现图片对比(一)

    前提 前阵子报了个班,学了一些android UI自动化相关的东西,于是想到第一家单位在做android手机自动化的时候,有用到图片对比,来确定是否点到指定的页面,遂想在appium+python做U ...

  9. vue3 内置组件keep-alive用法的全面介绍

    vue3 内置组件keep-alive用法的全面介绍 基础用法 首先看一个反面例子 const app = Vue.createApp({template: `<button v-for=&qu ...

  10. HarmonyOS第三方组件——鸿蒙图片裁剪组件ohos-Image-Cropper

    前言 基于安卓的平台的图片裁剪组件(https://github.com/ArthurHub/Android-Image-Cropper),实现了鸿蒙平台的迁移和重构,代码已经开源到(https:// ...

最新文章

  1. ★Kali信息收集~★6.Dmitry:汇总收集
  2. Java中实用类:Date、Calendar、Math、Random、String、StringBuffer的用法
  3. Python中的生成器与迭代器
  4. pytorch tensor查找0_Pytorch tensor(0): Tensor Introduction
  5. mysql5.6安装配置教程_Centos6.8 Mysql5.6 安装配置教程
  6. python123-python123练习题.doc
  7. ASP.NET MVC 不能加载项目的解决办法
  8. 2021年茶艺师(初级)考试总结及茶艺师(初级)作业考试题库
  9. 上海互联网整体沉沦:盛大巨人全没落 8年没出一个马云
  10. ArcGIS教程:填挖的工作原理
  11. Ethereum非同质化通证(NFT)的铸造与展示
  12. SCRUM项目 4.0
  13. Python 打开文件对话框
  14. SharePoint 16 规划大型文档存储库
  15. 人死了后还有来生吗?
  16. 交管12123服务器维护,交管12123服务异常怎么办?交管12123 APP服务异常解决方法...
  17. Edsger Wybe Dijkstra
  18. XMind6和XMind7有何不同
  19. 日程管理软件-MyAssistant
  20. win系统快捷键(最全)

热门文章

  1. tof传感器有什么用 tof传感器原理「手机百科」
  2. 数据安全分类分级剖析
  3. 现代信号处理 张贤达_信号处理领域著名科学家、清华大学张贤达教授逝世,享年 74岁...
  4. laravel与thinkphp相比有哪些优势?他们之间的区别/优缺点在哪
  5. 汇编 十六进制转二进制
  6. Booth算法运算原理
  7. sqlserver2016转sqlserver2008
  8. java实现人民币金额大写
  9. 2022年 6 款最佳免费电子邮件营销软件
  10. st7789 旋转_ESP32驱动ST7789液晶屏