当前位置: 首页 > news >正文

淄博网站建设专家网站开发平台有哪些

淄博网站建设专家,网站开发平台有哪些,应用商店app下载安装,某绿色园林企业网站源码图片叠加拖拽对比展示效果实现——Vue版 项目中遇见一个需求:2张图片按竖线分割,左右两侧分别展示对应图片,通过滚动条拖动对应展示图片区域;; 网上搜索了下,没有找到直接可用的组件,这里自己封装了一个次功…

图片叠加拖拽对比展示效果实现——Vue版

项目中遇见一个需求:2张图片按竖线分割,左右两侧分别展示对应图片,通过滚动条拖动对应展示图片区域;;
网上搜索了下,没有找到直接可用的组件,这里自己封装了一个次功能组件;后面会附上完整代码。,希望可以帮助到由此需求的小伙伴;

文章目录

  • 图片叠加拖拽对比展示效果实现——Vue版
    • 一、实现效果预览
    • 二、HTML 部分
      • 1. 组件包含:头部插槽、底部插槽、切换比较图片组
      • 2. 代码示例
    • 三、JS 部分
      • 1. 包含组件传参,左侧图片地址、右侧图片地址、事件处理等
      • 2. JS 部分代码如下:
    • 四、 CSS 样式代码
    • 六、完整使用示例

一、实现效果预览

在这里插入图片描述

二、HTML 部分

1. 组件包含:头部插槽、底部插槽、切换比较图片组

2. 代码示例

<template><div class="image-comparator"><!--  头部插槽  --><slot name="header"></slot><!--   切换对比图片  下一组、上一组 --><div class="prev" @click="prevFun"><i class="el-icon-arrow-left"></i></div><div class="next" @click="nextFun"><i class="el-icon-arrow-right"></i></div><!-- 核心标签代码   --><div class="container" @mouseenter="startDrag" @mousemove="onDrag" @mouseup="endDrag" @mouseleave="endDrag"><div class="image-wrapper":style="{ clipPath: `inset(0 ${100 - (dividerPosition / containerWidth * 100)}% 0 0)` }"><img src="https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg" class="image"/></div><div class="divider" :style="{ left: `${dividerPosition}px` }"></div><div class="image-wrapper" :style="{ clipPath: `inset(0 0 0 ${(dividerPosition / containerWidth * 100)}%)` }"><img src="https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg" class="image"/></div></div><!--  底部插槽  --><slot name="footer"></slot></div>
</template>

三、JS 部分

1. 包含组件传参,左侧图片地址、右侧图片地址、事件处理等

2. JS 部分代码如下:

<script>export default {name: 'imageComparator',props: {leftImgUrl: {type: String,},rightImgUrl: {type: String,},},data() {return {containerWidth: 500,dividerPosition: 250,dragging: false,containerRect: null,};},methods: {updateContainerWidth() {this.containerWidth = this.$el.querySelector('.container').clientWidth;},startDrag(event) {this.dragging = true;this.containerRect = this.$el.querySelector('.container').getBoundingClientRect();},onDrag(event) {if (this.dragging && this.containerRect) {let newPosition = event.clientX - this.containerRect.left;if (newPosition < 0) newPosition = 0;if (newPosition > this.containerRect.width) newPosition = this.containerRect.width;this.dividerPosition = newPosition;}},endDrag() {this.dragging = false;this.containerRect = null;},prevFun() {this.$emit('prevFun');},nextFun() {this.$emit('nextFun');},},mounted() {this.updateContainerWidth();window.addEventListener('resize', this.updateContainerWidth);},beforeDestroy() {window.removeEventListener('resize', this.updateContainerWidth);},};</script>

四、 CSS 样式代码

<style scoped lang="less">
.image-comparator {width: 90%;/*max-width: 600px;*/margin: 0 auto;.container {position: relative;width: 100%;height: 600px;overflow: hidden;}.image-wrapper {position: absolute;top: 0;left: 0;width: 100%;height: 100%;overflow: hidden;}.image {width: 100%;height: 100%;object-fit: cover;}.divider {position: absolute;top: 0;bottom: 0;width: 2px;background-color: black;cursor: ew-resize;z-index: 10;}.prev, .next {position: absolute;top: 50%;transform: translateY(-50%);z-index: 100;cursor: pointer;font-size: 40px;color: white;background-color: rgba(0, 0, 0, 0.5);padding: 10px;border-radius: 50%;transition: all 0.3s ease;left: 10px;&:hover {background-color: rgba(0, 0, 0, 0.8);color: #0bf4cb;}&.next {right: 10px;left: auto;}}
}</style>

## 五、总结

本文着重介绍了Vue2 封装的图片分割展示组件,如果小伙伴项目是V3 可以自行修改Vue 组件即可,还有写组件传参地方,需要的话自行改为动态参数即可,这里父组件不做过多介绍,以免浪费小伙伴看代码时间;

六、完整使用示例

以下是一个完整的 代码示例

<template><div class="image-comparator"><!--  头部插槽  --><slot name="header"></slot><!--   切换对比图片  下一组、上一组 --><div class="prev" @click="prevFun"><i class="el-icon-arrow-left"></i></div><div class="next" @click="nextFun"><i class="el-icon-arrow-right"></i></div><!-- 核心标签代码   --><div class="container" @mouseenter="startDrag" @mousemove="onDrag" @mouseup="endDrag" @mouseleave="endDrag"><div class="image-wrapper":style="{ clipPath: `inset(0 ${100 - (dividerPosition / containerWidth * 100)}% 0 0)` }"><img src="https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg" class="image"/></div><div class="divider" :style="{ left: `${dividerPosition}px` }"></div><div class="image-wrapper" :style="{ clipPath: `inset(0 0 0 ${(dividerPosition / containerWidth * 100)}%)` }"><img src="https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg" class="image"/></div></div><!--  底部插槽  --><slot name="footer"></slot></div>
</template><script>
export default {name: 'imageComparator',props: {leftImgUrl: {type: String,},rightImgUrl: {type: String,},},data() {return {containerWidth: 500,dividerPosition: 250,dragging: false,containerRect: null,};},methods: {updateContainerWidth() {this.containerWidth = this.$el.querySelector('.container').clientWidth;},startDrag(event) {this.dragging = true;this.containerRect = this.$el.querySelector('.container').getBoundingClientRect();},onDrag(event) {if (this.dragging && this.containerRect) {let newPosition = event.clientX - this.containerRect.left;if (newPosition < 0) newPosition = 0;if (newPosition > this.containerRect.width) newPosition = this.containerRect.width;this.dividerPosition = newPosition;}},endDrag() {this.dragging = false;this.containerRect = null;},prevFun() {this.$emit('prevFun');},nextFun() {this.$emit('nextFun');},},mounted() {this.updateContainerWidth();window.addEventListener('resize', this.updateContainerWidth);},beforeDestroy() {window.removeEventListener('resize', this.updateContainerWidth);},};
</script>
<style scoped lang="less">
.image-comparator {width: 90%;/*max-width: 600px;*/margin: 0 auto;.container {position: relative;width: 100%;height: 600px;overflow: hidden;}.image-wrapper {position: absolute;top: 0;left: 0;width: 100%;height: 100%;overflow: hidden;}.image {width: 100%;height: 100%;object-fit: cover;}.divider {position: absolute;top: 0;bottom: 0;width: 2px;background-color: black;cursor: ew-resize;z-index: 10;}.prev, .next {position: absolute;top: 50%;transform: translateY(-50%);z-index: 100;cursor: pointer;font-size: 40px;color: white;background-color: rgba(0, 0, 0, 0.5);padding: 10px;border-radius: 50%;transition: all 0.3s ease;left: 10px;&:hover {background-color: rgba(0, 0, 0, 0.8);color: #0bf4cb;}&.next {right: 10px;left: auto;}}
}</style>

看到这里的小伙伴,欢迎点赞、评论,收藏!

如有前端相关疑问,请评论区留言,博主会在第一时间解答!!!

http://www.hkea.cn/news/307637/

相关文章:

  • 淄博市 网站建设报价郑州seo外包阿亮
  • 网络服务商是指什么网站优化排名工具
  • 网站优化的分析比较好的品牌策划公司有哪些
  • 国外比较好的资源网站电商运营推广是做什么的
  • 佛山房地产网站建设seo实战培训王乃用
  • 如何做可以赚钱的网站关键词如何快速排名
  • 深圳品牌做网站公司有哪些百度app推广
  • 重庆建设行业信息网站搜狗登录入口
  • 同仁行业网站建设报价北京做的好的seo公司
  • 陕西自助建站做网站郑州外语网站建站优化
  • 小型企业网站系统cilimao磁力猫最新版地址
  • 铁岭网站建设移动网站广东网站seo
  • 网站模板插件sem和seo
  • 用wordpress制作网站模板沈阳seo
  • 优化一个网站多少钱宜昌网站seo
  • 刚做的网站怎么才能搜索到枸橼酸西地那非片功效效及作用
  • 罗湖区网站公司专业模板建站
  • 哪有备案好的网站国产系统2345
  • 网站开发怎么让别人看到最新营销模式有哪些
  • ssm网站开发源码百度推广多少钱一个月
  • 手游门户网站建设appstore关键词优化
  • 齐河网站开发seo服务内容
  • 北京微信网站建设费用想卖产品怎么推广宣传
  • 网站上线的步骤厦门网站推广公司哪家好
  • 网站做app的软件有哪些百度一下你就知道下载
  • 界面设计的重要性百度seo关键词排名推荐
  • 股票做T网站直播营销
  • 北京手机网站建设公司排名技术优化seo
  • wordpress可爱的主题seo优化教程
  • 自己可以申请网站做外卖吗网站描述和关键词怎么写