Jquery creates a layer that displays the title and content and moves with the mouse

  • 2020-03-30 01:27:58
  • OfStack

 
<script src="Core/Public/js/jquery.js" type="text/javascript"></script> //The introduction of the Jquery
<style type="text/css"> //Write the style of the div you created
#tooltip 
{ 
position: absolute; 
border: 1px #solid #333; 
background: #f7f5d1; 
padding: 1px; 
color: #333; 
display: none; 
} 
</style> 
<script type="text/javascript"> //Writing JS code
$(function () { 
var x = 10; 
var y = 10; 
$("a.tooltip").mouseover(function (e) { //When the mouse pointer moves over an element
this.myTitle = this.title; 
this.title = ""; 
var tooltip = "<div id='tooltip'>" + this.myTitle + "</div>"; 
$("body").append(tooltip); 
$("#tooltip").css({ "top": (e.pageY + y) + "px", "left": (e.pageX + x) + "px" }).show("fast"); 
}).mouseout(function () { //When the mouse pointer is removed from the element
this.title = this.myTitle; 
$("#tooltip").remove(); 
}).mousemove(function (e) { //When the mouse pointer moves over the element
$("#tooltip").css({ "top": (e.pageY + y) + "px", "left": (e.pageX + x) + "px" }); 
}); 
}); 
</script> 
//The HTML code
<ul> 
<li><a href="#" class="tooltip" title=" Sweet and loose sweater ">1111111111111</a></li> 
<li><a href="#" class="tooltip" title=" It's a show off in an ostentatious manner ">2222222222222</a></li> 
</ul> 

Related articles: