JS+DIV实现自定义Title的显示方式

简介:      自定义的title显示方式一直在华夏用,当你的鼠标悬停在带有提示的链接上时会有自定义的显示内容出现,显示的内容支持html代码,但是这个效果不支持firefox及其他浏览器,最近对之进行了改进,终于兼容了FF,Safari。代码如下:   var qTipTag = "a"; //Which tag do you want to qTip-ize? Keep it lowerc
     自定义的title显示方式一直在华夏用,当你的鼠标悬停在带有提示的链接上时会有自定义的显示内容出现,显示的内容支持html代码,但是这个效果不支持firefox及其他浏览器,最近对之进行了改进,终于兼容了FF,Safari。代码如下:
 
var qTipTag = "a"; //Which tag do you want to qTip-ize? Keep it lowercase!//
var qTipX = -30; //This is qTip's X offset//
var qTipY = 25; //This is qTip's Y offset//
 
//There's No need to edit anything below this line//
tooltip = {
  name : "qTip",
  offsetX : qTipX,
  offsetY : qTipY,
  tip : null
}
tooltip.init = function () {
 var tipNameSpaceURI = "
http://www.w3.org/1999/xhtml ";
 if(!tipContainerID){ var tipContainerID = "qTip";}
 var tipContainer = document.getElementById(tipContainerID);
 if(!tipContainer) {
   tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
  tipContainer.setAttribute("id", tipContainerID);
   document.getElementsByTagName("body").item(0).appendChild(tipContainer);
 }
 if (!document.getElementById) return;
 this.tip = document.getElementById (this.name);
 if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};
 var a, sTitle;
 var anchors = document.getElementsByTagName (qTipTag);
 for (var i = 0; i < anchors.length; i ++) {
  a = anchors[i];
  sTitle = a.getAttribute("title");
  if(sTitle) {
   a.setAttribute("tiptitle", sTitle);
   a.removeAttribute("title");
   a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
   a.onmouseout = function() {tooltip.hide()};
  }
 }
}
tooltip.move = function (evt) {
 var x=0, y=0;
 if (document.all) {//IE
  x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
  y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
  x += window.event.clientX;
  y += window.event.clientY;
  
 } else {//Good Browsers
  x = evt.pageX;
  y = evt.pageY;
 }
 this.tip.style.left = (x + this.offsetX) + "px";
 this.tip.style.top = (y + this.offsetY) + "px";
}
tooltip.show = function (text) {
 if (!this.tip) return;
 this.tip.innerHTML = text;
 this.tip.style.display = "block";
}
tooltip.hide = function () {
 if (!this.tip) return;
 this.tip.innerHTML = "";
 this.tip.style.display = "none";
}
window.onload = function () {
 tooltip.init ();
}
 
css样式:
/*tip div*/
div#qTip{
  border: 1px solid #99CC33;
  border-right-width: 2px;
  border-bottom-width: 2px;
  display: none;
  background: #fff;
  color: #000;
  font: 13px Verdana, Arial, Helvetica, sans-serif;
  text-align: left;
  position: absolute;
  z-index: 1000;
  padding: 8px;
}
 
相关文章
|
8月前
|
开发框架 前端开发 JavaScript
在Vue&Element前端项目中,使用FastReport + pdf.js生成并展示自定义报表
在Vue&Element前端项目中,使用FastReport + pdf.js生成并展示自定义报表
|
10月前
|
前端开发 JavaScript
使用JavaScript实现复杂功能:构建一个自定义的拖拽功能
使用JavaScript实现复杂功能:构建一个自定义的拖拽功能
|
7月前
|
存储 前端开发 JavaScript
javascript 异常问题之为自定义异常提供丰富的上下文信息如何实现
javascript 异常问题之为自定义异常提供丰富的上下文信息如何实现
|
5月前
|
JavaScript 前端开发
js怎么获取div里面的文字长度
js怎么获取div里面的文字长度
81 5
|
5月前
|
移动开发 JavaScript 前端开发
原生js如何获取dom元素的自定义属性
原生js如何获取dom元素的自定义属性
141 4
|
7月前
|
前端开发 微服务 API
微服务浪潮下的JSF革新:如何在分散式架构中构建统一而强大的Web界面
【8月更文挑战第31天】随着微服务架构的兴起,企业将应用拆分成小型、独立的服务以提高系统可维护性和可扩展性。本文探讨如何在微服务架构下构建和部署JavaServer Faces (JSF) 应用,通过RESTful服务实现前后端分离,提升灵活性和适应性。
79 1
|
6月前
|
JavaScript 前端开发
网页前端课程设计-【模仿】香港中文大学官网,轮播图及div+css布局,js的dom操作
这篇文章介绍了如何模仿香港中文大学官网进行网页前端课程设计,包括使用div+css布局、js的DOM操作以及实现轮播图等技术细节。
|
7月前
|
前端开发 程序员
HTML+CSS+JavaScript制作动态七夕表白网页(含音乐+自定义文字)
一年一度的520情人节/七夕情人节/女朋友生日/程序员表白,是不是要给女朋友或者正在追求的妹子一点小惊喜呢,今天这篇博客就分享下前端代码如何实现HTML+CSS+JavaScript制作七夕表白网页(含音乐+自定义文字)。赶紧学会了,来制作属于我们程序员的浪漫吧!
232 0
|
7月前
|
JavaScript 前端开发
js怎么获取div里面的文字长度
js怎么获取div里面的文字长度
71 3
|
8月前
|
JavaScript NoSQL Serverless
函数计算产品使用问题之如何创建一个自定义运行时并指定Node.js版本
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。
105 8

热门文章

最新文章