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

网站开发公司的义务苏州做网站便宜的公司

网站开发公司的义务,苏州做网站便宜的公司,怎么做木马网站,广东万泰建设有限公司网站Vue实现悬浮图片弹出大图预览弹窗,弹窗顶部与图片顶部平齐 需求背景 当前项目内某页面左侧展示图片列表,图片列表展示的均为小图。需求希望鼠标移动到对应图片时,右侧出现大图预览弹窗,且该弹窗顶部需与图片顶部平齐。同时弹窗要…

Vue实现悬浮图片弹出大图预览弹窗,弹窗顶部与图片顶部平齐

在这里插入图片描述

需求背景

当前项目内某页面左侧展示图片列表,图片列表展示的均为小图。需求希望鼠标移动到对应图片时,右侧出现大图预览弹窗,且该弹窗顶部需与图片顶部平齐。同时弹窗要在页面中展示完全,不能超出窗口高度导致被遮挡

核心实现

1.获取悬浮图片的位置信息

<div class="image_item" v-for="(item, index) in imgList" :key="index"><img:src="item"class="img"@mouseenter="e => handlePreview(e, item)"@mouseleave="preview.show = false"/>
</div>
// 获取当前图片顶部与视口顶部的距离top和底部的距离bottom
const handlePreview = (e, url) => {const targetRect = e.target.getBoundingClientRect()preview.bottom = window.innerHeight - targetRect.toppreview.top = targetRect.toppreview.url = urlpreview.show = true
}

2.动态计算大图预览弹窗位置

<!-- 样式绑定计算属性,根据悬浮图片位置变化 -->
<div class="module_view" v-show="preview.show" :style="previewStyle"><img :src="preview.url" class="img" />
</div>
const previewStyle = computed(() => {// 弹窗实际高度const previewHeight = 538const container = listRef.value// 容器与视口顶部距离const containerTop = container ? container.getBoundingClientRect().top : 0const previewTop = preview.topconst previewBottom = preview.bottom// 弹窗顶部与容器顶部的距离let top = previewTop - containerToplet bottom = previewBottom - previewHeight// 判断弹窗顶部与视口底部的距离是否能容纳整个弹窗if (bottom < 0) {// 无法容纳时,减小弹窗顶部距离容器顶部的距离从而抬升弹窗// 还需判断抬升后弹窗顶部与视口顶部是否仍大于0,否则设置为置顶距离,即负的容器与视口顶部距离top = previewTop + bottom > 0 ? top + bottom : 0 - containerTop}return {top: top + 'px'}
})

完整代码

<!-- 实现图片悬浮右侧展开预览大图弹窗功能,弹窗顶部与图片顶部平齐 -->
<template><div class="image_view"><div class="image_list" ref="listRef"><div class="image_item" v-for="(item, index) in imgList" :key="index"><img:src="item"class="img"@mouseenter="e => handlePreview(e, item)"@mouseleave="preview.show = false"/></div><div class="module_view" v-show="preview.show" :style="previewStyle"><img :src="preview.url" class="img" /></div></div></div>
</template><script>
import { defineComponent, ref, reactive, computed } from 'vue'
import { getImg } from '@/utils/imgExample'export default defineComponent({setup() {const imgList = ref(getImg(0, 12))const listRef = ref(null)const preview = reactive({top: 0,bottom: 0,url: '',show: false})const previewStyle = computed(() => {// 弹窗实际高度const previewHeight = 538const container = listRef.value// 容器与视口顶部距离const containerTop = container ? container.getBoundingClientRect().top : 0const previewTop = preview.topconst previewBottom = preview.bottom// 弹窗顶部与容器顶部的距离let top = previewTop - containerToplet bottom = previewBottom - previewHeight// 判断弹窗顶部与视口底部的距离是否能容纳整个弹窗if (bottom < 0) {// 无法容纳时,减小弹窗顶部距离容器顶部的距离从而抬升弹窗// 还需判断抬升后弹窗顶部与视口顶部是否仍大于0,否则设置为置顶距离,即负的容器与视口顶部距离top = previewTop + bottom > 0 ? top + bottom : 0 - containerTop}return {top: top + 'px'}})// 获取当前图片顶部与视口顶部的距离top和底部的距离bottomconst handlePreview = (e, url) => {const targetRect = e.target.getBoundingClientRect()preview.bottom = window.innerHeight - targetRect.toppreview.top = targetRect.toppreview.url = urlpreview.show = true}return {listRef,imgList,preview,previewStyle,handlePreview}}
})
</script><style lang="less" scoped>
.image_view {width: 100%;height: 100%;.image_list {position: relative;width: 404px;height: 100%;padding: 12px;border: 1px solid #ededed;display: flex;flex-wrap: wrap;gap: 8px;.image_item {width: 120px;height: 120px;border-radius: 4px;overflow: hidden;.img {width: 100%;height: 100%;object-fit: cover;}}.module_view {position: absolute;top: 0;right: -404px;width: 400px;height: 528px;background: #fff;box-shadow: 0 4px 10px 2px rgba(0, 0, 0, 0.16);padding: 8px;border-radius: 12px;}}
}
</style>
http://www.yayakq.cn/news/948672/

相关文章:

  • 代做论文的网站有哪些好的美丽说的网站建设
  • 域名反查网站wordpress 插件定制
  • 网站前端开发流程网站建设用什么软件做
  • 浙江网站建设推广公司网站开发gif图太多耗资源吗
  • 网站优化自已做还是请人做百度统计工具
  • 表白网站源码大全浅谈博星卓越网站建设
  • 吴堡网站建设费用广州网站建设设计哪家好
  • 免费域名网站申请263企业邮箱入口登录找回密码
  • 华为公司网站建设分析评价国内saas软件公司排名
  • 南通网站建设制作公司怎么对网站链接做拆解
  • 网站备案无前置审批文件企业官网型网站模板下载
  • 商城系统网站建设开发重写Wordpress的js
  • 医院类网站建设与维护建设国际互联网网站
  • 如何做网站授权做设计有必要买素材网站会员
  • 模板网站与定制开发网站的区别深圳建网站的
  • 西安学校网站建设公司辽宁省工程建设信息网官网
  • 免费企业网站建设免费池州网站制作公
  • 为网站制定推广计划wordpress的管理员权限代码
  • 拥有服务器后如何做网站建设400官方网站
  • 阿里云1核2g服务器能建设几个网站网站seo竞争分析工具
  • 律师事务所网站建设重要性医院客户做网站找谁
  • 网站排名优化提升快速软件的开发定制
  • 做外贸兼职的网站设计户网站开发的小公司
  • 知名企业网站人才招聘情况室内设计考研
  • 东莞网站建设团队全网天下wordpress 改手机版
  • 查看网站流量网站发号源码2016
  • 高要住房和城乡建设局网站重庆教育网站建设
  • 网站建设shundeit网站下载免费的视频软件
  • 企业网站建设培训nas wordpress建站
  • 做一个网站要多少钱买了域名如何建立网站