279 lines
9.0 KiB
HTML
279 lines
9.0 KiB
HTML
<!doctype html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>12方向Tooltip</title>
|
|
<style>
|
|
/* 基础样式 */
|
|
body {
|
|
min-height: 100vh;
|
|
margin: 0;
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 2rem;
|
|
padding: 2rem;
|
|
background: #f0f2f5;
|
|
}
|
|
|
|
.trigger {
|
|
padding: 0.8rem 1.6rem;
|
|
border: none;
|
|
border-radius: 6px;
|
|
background: #2196f3;
|
|
color: white;
|
|
font-size: 1rem;
|
|
cursor: pointer;
|
|
transition: opacity 0.2s;
|
|
}
|
|
|
|
.trigger:hover {
|
|
opacity: 0.9;
|
|
}
|
|
|
|
/* Tooltip 核心样式 */
|
|
.tooltip {
|
|
position: fixed;
|
|
z-index: 10000;
|
|
min-width: 60px;
|
|
max-width: 240px;
|
|
padding: 0.8rem 1.2rem;
|
|
background: rgba(0, 0, 0, 0.8);
|
|
color: white;
|
|
font-size: 0.9rem;
|
|
line-height: 1.4;
|
|
border-radius: 4px;
|
|
visibility: hidden;
|
|
opacity: 0;
|
|
transition:
|
|
opacity 0.2s,
|
|
visibility 0.2s;
|
|
pointer-events: none;
|
|
}
|
|
|
|
/* 箭头通用样式 */
|
|
.tooltip::after {
|
|
content: '';
|
|
position: absolute;
|
|
width: 0;
|
|
height: 0;
|
|
border: 6px solid transparent;
|
|
}
|
|
|
|
/* 不同方向的样式 */
|
|
/* 上方系列 */
|
|
.tooltip.top {
|
|
transform: translate(-50%, calc(-100% - 12px));
|
|
}
|
|
.tooltip.top::after {
|
|
bottom: -12px;
|
|
left: 50%;
|
|
transform: translateX(-50%);
|
|
border-top-color: rgba(0, 0, 0, 0.8);
|
|
}
|
|
|
|
.tooltip.top-left {
|
|
transform: translate(calc(-100% + 12px), calc(-100% - 12px));
|
|
}
|
|
.tooltip.top-left::after {
|
|
bottom: -12px;
|
|
left: 12px;
|
|
border-top-color: rgba(0, 0, 0, 0.8);
|
|
}
|
|
|
|
.tooltip.top-right {
|
|
transform: translate(12px, calc(-100% - 12px));
|
|
}
|
|
.tooltip.top-right::after {
|
|
bottom: -12px;
|
|
right: 12px;
|
|
border-top-color: rgba(0, 0, 0, 0.8);
|
|
}
|
|
|
|
/* 下方系列 */
|
|
.tooltip.bottom {
|
|
transform: translate(-50%, 12px);
|
|
}
|
|
.tooltip.bottom::after {
|
|
top: -12px;
|
|
left: 50%;
|
|
transform: translateX(-50%);
|
|
border-bottom-color: rgba(0, 0, 0, 0.8);
|
|
}
|
|
|
|
.tooltip.bottom-left {
|
|
transform: translate(calc(-100% + 12px), 12px);
|
|
}
|
|
.tooltip.bottom-left::after {
|
|
top: -12px;
|
|
left: 12px;
|
|
border-bottom-color: rgba(0, 0, 0, 0.8);
|
|
}
|
|
|
|
.tooltip.bottom-right {
|
|
transform: translate(12px, 12px);
|
|
}
|
|
.tooltip.bottom-right::after {
|
|
top: -12px;
|
|
right: 12px;
|
|
border-bottom-color: rgba(0, 0, 0, 0.8);
|
|
}
|
|
|
|
/* 左侧系列 */
|
|
.tooltip.left {
|
|
transform: translate(calc(-100% - 12px), -50%);
|
|
}
|
|
.tooltip.left::after {
|
|
right: -12px;
|
|
top: 50%;
|
|
transform: translateY(-50%);
|
|
border-left-color: rgba(0, 0, 0, 0.8);
|
|
}
|
|
|
|
.tooltip.left-top {
|
|
transform: translate(calc(-100% - 12px), calc(-100% + 12px));
|
|
}
|
|
.tooltip.left-top::after {
|
|
right: -12px;
|
|
top: 12px;
|
|
border-left-color: rgba(0, 0, 0, 0.8);
|
|
}
|
|
|
|
.tooltip.left-bottom {
|
|
transform: translate(calc(-100% - 12px), 12px);
|
|
}
|
|
.tooltip.left-bottom::after {
|
|
right: -12px;
|
|
bottom: 12px;
|
|
border-left-color: rgba(0, 0, 0, 0.8);
|
|
}
|
|
|
|
/* 右侧系列 */
|
|
.tooltip.right {
|
|
transform: translate(12px, -50%);
|
|
}
|
|
.tooltip.right::after {
|
|
left: -12px;
|
|
top: 50%;
|
|
transform: translateY(-50%);
|
|
border-right-color: rgba(0, 0, 0, 0.8);
|
|
}
|
|
|
|
.tooltip.right-top {
|
|
transform: translate(12px, calc(-100% + 12px));
|
|
}
|
|
.tooltip.right-top::after {
|
|
left: -12px;
|
|
top: 12px;
|
|
border-right-color: rgba(0, 0, 0, 0.8);
|
|
}
|
|
|
|
.tooltip.right-bottom {
|
|
transform: translate(12px, 12px);
|
|
}
|
|
.tooltip.right-bottom::after {
|
|
left: -12px;
|
|
bottom: 12px;
|
|
border-right-color: rgba(0, 0, 0, 0.8);
|
|
}
|
|
|
|
/* 显示状态 */
|
|
.tooltip.visible {
|
|
visibility: visible;
|
|
opacity: 1;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div style="text-align: center;"><table border="1"><tbody><tr><td colspan="4">Shipper: CHANNEL INTERNATIONAL FREIGHT CO.,LTD 24 FLOOR, YINYI GLOBAL CENTER,B BLOCK,NO.42 YAOHANG STREET HAISHUDISTRICT,NINGBO,CHINA TEL:0086-574-87337359 FAX:0086-574-87135310</td><td rowspan="3" colspan="4">TO:宁波坤洲国际物流有限公司 ATTN: TEL: FROM:宁波驰诺/裘珊珊 TEL:0574-87237893 QQ:1597608137 业务编号:CNNBYS230201 开航日期:2023-02-0400:00:00.0 船公司:现代商船 柜量:2X2OTKFCL运费条款:FREIGHTPREPAID 运输条款:CY-CY</td></tr><tr><td colspan="4">Consignee: NSINTERNATIONAL(THAILAND)CO.LTD 75/49 RICHMOND BLDG.,15 FL SUKHUMVIT SOI 26 KLONGTOEY,BANGKOK1011O THAILAND ATTN:IMPORT@NSINTER.COM TEL: +66-2-665-6710 FAX:+66-2-665-6494</td></tr><tr><td colspan="4">Notify Party: NS INTERNATIONAL (THAILAND) CO.,LTD 75/49 RICHMOND BLDG., 15 FL SUKHUMVIT SOI 26 KLONGTOEY,BANGKOK1011O THAILAND ATTN:IMPORT@NSINTER.COM TEL:+66-2-665-6710 FAX: +66-2-665-6494</td></tr><tr><td colspan="2">起运港(PortOf Loading):</td><td colspan="3">中转港(Port of Dischargc):</td><td colspan="3">目的港(Final Destination):</td></tr><tr><td colspan="2">NINGBO,CHINA</td><td colspan="3"></td><td colspan="3">LEAM CHA BANG</td></tr><tr><td>标志和号码</td><td colspan="2">件数和包装种类</td><td colspan="3">货名</td><td>毛重(公斤)</td><td>体积(立方米)</td></tr><tr><td>SMAU9992165 SMAU9992170</td><td colspan="2">2TANKS</td><td colspan="3">BULK LIQUID ARGON CLASS:2.2 UN:1951</td><td>44000.000KGS</td><td>50.000CBM</td></tr></tbody></table></div>
|
|
|
|
<script>
|
|
class TooltipManager {
|
|
constructor() {
|
|
this.tooltip = null
|
|
this.init()
|
|
}
|
|
|
|
init() {
|
|
// 创建tooltip元素
|
|
this.tooltip = document.createElement('div')
|
|
this.tooltip.className = 'tooltip'
|
|
document.body.appendChild(this.tooltip)
|
|
|
|
// 绑定触发事件
|
|
document.querySelectorAll('.trigger').forEach((trigger) => {
|
|
trigger.addEventListener('mouseenter', (e) => this.show(e))
|
|
trigger.addEventListener('mouseleave', () => this.hide())
|
|
})
|
|
}
|
|
|
|
show(e) {
|
|
const { direction } = e.target.dataset
|
|
const text = e.target.dataset.tooltip
|
|
const triggerRect = e.target.getBoundingClientRect()
|
|
|
|
// 设置内容
|
|
this.tooltip.textContent = text
|
|
this.tooltip.className = `tooltip ${direction}`
|
|
|
|
// 计算初始位置
|
|
const { offsetWidth: tw, offsetHeight: th } = this.tooltip
|
|
const { left: tx, top: ty, width: trw, height: thr } = triggerRect
|
|
const offset = 12 // 基础偏移量
|
|
|
|
// 方向位置映射
|
|
const positionMap = {
|
|
top: { left: tx + trw / 2, top: ty - th - offset },
|
|
'top-left': { left: tx + trw - 12, top: ty - th - offset },
|
|
'top-right': { left: tx + 12, top: ty - th - offset },
|
|
bottom: { left: tx + trw / 2, top: ty + thr + offset },
|
|
'bottom-left': { left: tx + trw - 12, top: ty + thr + offset },
|
|
'bottom-right': { left: tx + 12, top: ty + thr + offset },
|
|
left: { left: tx - tw - offset, top: ty + thr / 2 },
|
|
'left-top': { left: tx - tw - offset, top: ty + 12 },
|
|
'left-bottom': { left: tx - tw - offset, top: ty + thr - 12 },
|
|
right: { left: tx + trw + offset, top: ty + thr / 2 },
|
|
'right-top': { left: tx + trw + offset, top: ty + 12 },
|
|
'right-bottom': { left: tx + trw + offset, top: ty + thr - 12 },
|
|
}
|
|
|
|
// 获取计算后的位置
|
|
let { left, top } = positionMap[direction]
|
|
|
|
// 边界检测(防止超出视口)
|
|
const viewportWidth = window.innerWidth
|
|
const viewportHeight = window.innerHeight
|
|
|
|
// 水平方向边界处理
|
|
if (left < 0)
|
|
left = 12 // 左边界
|
|
else if (left + tw > viewportWidth) left = viewportWidth - tw - 12 // 右边界
|
|
|
|
// 垂直方向边界处理
|
|
if (top < 0)
|
|
top = 12 // 上边界
|
|
else if (top + th > viewportHeight) top = viewportHeight - th - 12 // 下边界
|
|
|
|
// 应用位置
|
|
this.tooltip.style.left = `${left}px`
|
|
this.tooltip.style.top = `${top}px`
|
|
|
|
// 显示tooltip
|
|
requestAnimationFrame(() => {
|
|
this.tooltip.classList.add('visible')
|
|
})
|
|
}
|
|
|
|
hide() {
|
|
this.tooltip.classList.remove('visible')
|
|
}
|
|
}
|
|
|
|
// 初始化Tooltip管理器
|
|
new TooltipManager()
|
|
</script>
|
|
</body>
|
|
</html>
|