import Vue from 'vue'
Vue.directive('showTips',{
inserted(el) {
},
bind : function (el, binding, vnode) {
el.onmouseenter = function (e) {
console.log(el.scrollHeight);
console.log(el.clientHeight);
// if(el.scrollHeight>41){
if(el.scrollHeight>el.clientHeight){
// 创建浮层元素并设置样式
const vcTooltipDom = document.createElement('div')
// 设置id方便寻找
vcTooltipDom.setAttribute('id', 'vc-tooltip')
// 将浮层插入到body中
document.body.appendChild(vcTooltipDom)
// el.parentNode.appendChild(vcTooltipDom)
// console.log('vcTooltipDom===',vcTooltipDom);
// 浮层中的文字
document.getElementById('vc-tooltip').innerHTML = el.innerText
// console.log('高=====',vcTooltipDom.scrollHeight);
vcTooltipDom.style.cssText = `
max-width:800px;
min-width:150px;
overflow: auto;
position: fixed;
top:${e.clientY+20}px;
left:${e.clientX - e.offsetX}px;
background: rgba(0, 0 , 0, .6);
color:#fff;
border-radius:5px;
padding:10px;
line-height:20px;
display:inline-block;
font-size:12px;
z-index:19999
`
}
}
// 鼠标移出
el.onmouseleave = function () {
const vcTooltipDom = document.getElementById('vc-tooltip')
vcTooltipDom && document.body.removeChild(vcTooltipDom)
}
},
unbind: function (el) {
// 找到浮层元素并移除
const vcTooltipDom = document.getElementById('vc-tooltip')
vcTooltipDom && document.body.removeChild(vcTooltipDom)
}
})