欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery實(shí)現(xiàn)鼠標(biāo)移到某個(gè)對(duì)象時(shí)彈出顯示層功能

 更新時(shí)間:2018年08月23日 08:31:43   作者:jopen  
這篇文章主要介紹了jQuery實(shí)現(xiàn)鼠標(biāo)移到某個(gè)對(duì)象時(shí)彈出顯示層功能,涉及jQuery基于事件響應(yīng)動(dòng)態(tài)操作頁(yè)面元素屬性相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了jQuery實(shí)現(xiàn)鼠標(biāo)移到某個(gè)對(duì)象時(shí)彈出顯示層功能。分享給大家供大家參考,具體如下:

/**
* 鼠標(biāo)移上去顯示層
* @param divId 顯示的層ID
* @returns
*/
$.fn.myHoverTip = function(divId) {
  var div = $("#" + divId); //要浮動(dòng)在這個(gè)元素旁邊的層
  div.css("position", "absolute");//讓這個(gè)層可以絕對(duì)定位
  var self = $(this); //當(dāng)前對(duì)象
  self.hover(function() {
    div.css("display", "block");
    var p = self.position(); //獲取這個(gè)元素的left和top
    var x = p.left + self.width();//獲取這個(gè)浮動(dòng)層的left
    var docWidth = $(document).width();//獲取網(wǎng)頁(yè)的寬
    if (x > docWidth - div.width() - 20) {
    x = p.left - div.width();
    }
    div.css("left", x);
    div.css("top", p.top);
    div.show();
  },
  function() {
    div.css("display", "none");
  }
  );
  return this;
}

在哪個(gè)對(duì)象旁邊顯示DIV,隨自己定義,只要定義一個(gè)ID即可:

如:

<a id="viewReInfo" href="#" rel="external nofollow" rel="external nofollow" >查看收件人回執(zhí)情況</a>

需要顯示的DIV,根據(jù)需求自己定義,同樣只需定義ID即可:

如:

<div id="receiptInfo" class="receiptInfo">(www.dbjr.com.cn 提示信息)</div>

調(diào)用上面的JS函數(shù),代碼如下:

$('#viewReInfo').myHoverTip('receiptInfo');

測(cè)試示例如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>www.dbjr.com.cn jQuery彈出提示框</title>
<style>
.receiptInfo{display:none;}
</style>
</head>
<body>
<a id="viewReInfo" href="#" rel="external nofollow" rel="external nofollow" >查看收件人回執(zhí)情況</a>
<div id="receiptInfo" class="receiptInfo">(www.dbjr.com.cn 提示信息)</div>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
/**
* 鼠標(biāo)移上去顯示層
* @param divId 顯示的層ID
* @returns
*/
$.fn.myHoverTip = function(divId) {
  var div = $("#" + divId); //要浮動(dòng)在這個(gè)元素旁邊的層
  div.css("position", "absolute");//讓這個(gè)層可以絕對(duì)定位
  var self = $(this); //當(dāng)前對(duì)象
  self.hover(function() {
    div.css("display", "block");
    var p = self.position(); //獲取這個(gè)元素的left和top
    var x = p.left + self.width();//獲取這個(gè)浮動(dòng)層的left
    var docWidth = $(document).width();//獲取網(wǎng)頁(yè)的寬
    if (x > docWidth - div.width() - 20) {
    x = p.left - div.width();
    }
    div.css("left", x);
    div.css("top", p.top);
    div.show();
  },
  function() {
    div.css("display", "none");
  }
  );
  return this;
}
$('#viewReInfo').myHoverTip('receiptInfo');
</script>
</body>
</html>

PS:感興趣的朋友可以使用在線(xiàn)HTML/CSS/JavaScript代碼運(yùn)行工具http://tools.jb51.net/code/HtmlJsRun測(cè)試一下運(yùn)行效果。

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《jQuery窗口操作技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery常見(jiàn)經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)

希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論