";
$('body').append(str ); //この要素をページに追加します。スタイルは上記のように記述されています
$(".TipDiv").css({"top":yy "px","left":xx "px"} );// 要素が表示される位置を設定します (ここではマウスの右 10 ピクセル下に表示されます)
}
The result is as follows (when the mouse points to the third piece of data, the box pops up and moves with the mouse):
To do this, members have a new requirement, that is, do not allow the pop-up box to move with the movement of the mouse. In this way, once the mouse leaves the focus, the pop-up box will be removed. Not very convenient. They requested that the pop-up box be fixed, assuming it is on the right side of the corresponding data row, and that opening and closing is controlled by the members themselves, so Ben made improvements...
Similarly, first design a Div with the id of tips. Element, the style is as follows:
#tips
{
background-color: white;
border-left: 1px solid #a6c9e2;
border-right: 1px solid #a6c9e2;
border-top:5px solid #a6c9e2;
border-bottom :5px solid #a6c9e2;
width:268px; height:60px;
z-index:9;
position:absolute;
-moz-border-radius: 5px; -webkit-border- radius: 5px;
padding:8px 18px;
}
/* The pop-up layer’s pointing icon, left: -10 makes it appear on the left side of the entire Div*/
#tips #tipsArrow { position:absolute; top:26px; left: -10px }
#tips #light
{
width:36px;
height:36px;
margin:6px 16px 16px 16px;
float:left;
}
#tips span
{
margin-top:18px;
}
#tips #close
{
width:20px;
height:16px;
border:none;
z-index:1;
left:280px;
top:6px;
position:absolute;
cursor:pointer ;
}
The script is as follows:
$(document).ready(function(){
//Time mouseover
$("ul li span").mouseover(function(){
$("#tips ").remove();
var elem= $(this).parent();
var mTop=elem.offset().top;//Get the top coordinate of the element
var mLeft= elem.offset().left;//Get the left coordinate of the element
var addLeft=elem.width();//Get the width of the element
var finalTop=mTop-30;//Get the final element The Top position that appears. At this time, -30 elements are used to increase the height of this Div and let the arrow point to the corresponding row
var finalleft=mLeft addLeft 20; // To get the final element that appears Left, add the left side of the corresponding row plus the row width. The last 20 empty elements
var num=$("li").index(elem) 1;
popDiv1(finalTop,finalleft,"The prompt box reminds you that this is the "num" row of data!") ;
})
})
//Fixed message box
function popDiv1(tops,lefts,messages)
{
var str="";
str= "
";
$('body').append(str);
$("#tips").css({"top":tops "px","left" :lefts "px"});
}
function closeUp()
{
$("#tips").remove();
}
The final display effect is as follows:
Move the mouse over the corresponding data row to display the corresponding prompt box. The small cross icon on the right is used to close the entire pop-up layer...
Design summary:
The key to this design process is position: absolute (absolute positioning, used to allow layers to overlap on the page), z-index (used to display the stacking order of layers), top, left (display pop-up page coordinates), (offset().left,offset().top) Find the coordinates of an element on the page. Once the position is found, you can freely position the pop-up layer around it. Other styles can be adjusted at will according to your own art needs. ...
Source code downloadhttp://xiazai.jb51.net/201010/yuanma/popDiv.rar