JS代码:
setTipPop();
function setTipPop(){
let $tips = $(".tip-pop");
for (let i = 0; i < $tips.length; i++) {
let $tip = $($tips[i])
$tip.css("display", "inline-block");
$tip.css("color", "#5bbcff");
$tip.css("position", "relative");
let htmlText = $tip.html()
let id = "tip-pop-"+i;
$tip.html(`<div id="${id}-ico" style="display: inline-block" class="fa fa-question-circle-o tip-pop"></div>`)
$('#'+id+'-ico').hover(function () {
if ( $("#"+id).length===0){
$tip.append(
`<div id="${id}" style="position: absolute;top: 25px;left: -17px;width: 300px;z-index: 9999;background: rgba(50,50,50,0.9);padding: 10px;color: white;display: none">`+
'<div style="height: 12px;width: 12px;position: absolute;top:-5px;left: 18px;background: rgba(50,50,50,0.5);z-index: 0;transform: rotate(45deg)"></div>'+
`${htmlText}</div>`
)
}
$("#"+id).fadeIn(300);
}, function () {
$("#"+id).fadeOut(300);
})
}
}
HTML使用:
<span class="tip-pop" >
混合计算工资指通过xxxxxxxxx。<br><br>计算公式: xxxxxxxxxxx
</span>
需要有jquery和Font Awesome图标库, 也可以自己稍微改改, 去掉 jquery和Font Awesome