<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./jq-min.js"></script>
<style>
#mytitle{
position: absolute;
color: #fff;
font-size: 14px;
padding: 4px;
background: red;
z-index: 999;
}
.mytooltip{
display: inline-block;
width: 100px;
height: 100px;
background-color: pink;
}
</style>
</head>
<body>
<span class="mytooltip" title="样式"></span>
<script>
$(function(){
var newtitle = "";
$('span.mytooltip').mouseover(function(e){
newtitle = this.title;
this.title = "";
if(newtitle != ""){
$("body").append(`<div id='mytitle'>${newtitle}</div>`)
}
$("#mytitle").css({
'left':(e.pageX+'px'),
'top':(e.pageY+'px')
}).show();
}).mouseout(function(){
this.title = newtitle;
$("#mytitle").remove();
}).mousemove(function(e){
$("#mytitle").css({
'left':(e.pageX+10+'px'),
'top':(e.pageY+10+'px')
}).show();
})
})
</script>
</body>
</html>
标签title属性自定义样式
最新推荐文章于 2024-06-10 14:22:01 发布