CSS+js实现的一个优秀的超链接鼠标悬停提示

css|js|链接|鼠标

  超链接,一般的做法是给一个title属性,这样用户的鼠标悬停在超链接上的时候,它会显示title的内容。但是,你是否厌倦了千篇一律的鼠标悬停效果呢?
  当然,也有这方面很炫的代码,但是才跨浏览器方面功夫还是不够,呵呵。我遇到一个不错的css,在IE和Firefox下浏览一样的效果。
  实际的效果大家可以参考:校园招聘一网打尽(http://www.xyzp.net/)、http://www.xyzp.net/index.html

代码如下:
/*************************************************************************

dw_viewport.js
version date Nov 2003

This code is from Dynamic Web Coding
at http://www.dyn-web.com/
Copyright 2003 by Sharon Paine
See Terms of Use at http://www.dyn-web.com/bus/terms.html
regarding conditions under which you may use this code.
This notice must be retained in the code as is!

*************************************************************************/

var viewport = {
getWinWidth: function () {
this.width = 0;
if (window.innerWidth) this.width = window.innerWidth - 18;
else if (document.documentElement && document.documentElement.clientWidth)
this.width = document.documentElement.clientWidth;
else if (document.body && document.body.clientWidth)
this.width = document.body.clientWidth;
},

getWinHeight: function () {
this.height = 0;
if (window.innerHeight) this.height = window.innerHeight - 18;
else if (document.documentElement && document.documentElement.clientHeight)
this.height = document.documentElement.clientHeight;
else if (document.body && document.body.clientHeight)
this.height = document.body.clientHeight;
},

getScrollX: function () {
this.scrollX = 0;
if (typeof window.pageXOffset == "number") this.scrollX = window.pageXOffset;
else if (document.documentElement && document.documentElement.scrollLeft)
this.scrollX = document.documentElement.scrollLeft;
else if (document.body && document.body.scrollLeft)
this.scrollX = document.body.scrollLeft;
else if (window.scrollX) this.scrollX = window.scrollX;
},

getScrollY: function () {
this.scrollY = 0;
if (typeof window.pageYOffset == "number") this.scrollY = window.pageYOffset;
else if (document.documentElement && document.documentElement.scrollTop)
this.scrollY = document.documentElement.scrollTop;
else if (document.body && document.body.scrollTop)
this.scrollY = document.body.scrollTop;
else if (window.scrollY) this.scrollY = window.scrollY;
},

getAll: function () {
this.getWinWidth(); this.getWinHeight();
this.getScrollX(); this.getScrollY();
}

}

/*************************************************************************
dw_event.js (version date Feb 2004)

This code is from Dynamic Web Coding at http://www.dyn-web.com/
See Terms of Use at http://www.dyn-web.com/bus/terms.html
regarding conditions under which you may use this code.
This notice must be retained in the code as is!
*************************************************************************/

var dw_event = {

add: function(obj, etype, fp, cap) {
cap = cap || false;
if (obj.addEventListener) obj.addEventListener(etype, fp, cap);
else if (obj.attachEvent) obj.attachEvent("on" + etype, fp);
},

remove: function(obj, etype, fp, cap) {
cap = cap || false;
if (obj.removeEventListener) obj.removeEventListener(etype, fp, cap);
else if (obj.detachEvent) obj.detachEvent("on" + etype, fp);
},

DOMit: function(e) {
e = e? e: window.event;
e.tgt = e.srcElement? e.srcElement: e.target;

if (!e.preventDefault) e.preventDefault = function () { return false; }
if (!e.stopPropagation) e.stopPropagation = function ()
{ if (window.event) window.event.cancelBubble = true; }

return e;
}

}
/*************************************************************************
dw_tooltip.js requires: dw_event.js and dw_viewport.js
version date: March 14, 2005
(minor changes in position algorithm and timer mechanism)

This code is from Dynamic Web Coding at dyn-web.com
Copyright 2003-5 by Sharon Paine
See Terms of Use at www.dyn-web.com/bus/terms.html
regarding conditions under which you may use this code.
This notice must be retained in the code as is!
*************************************************************************/

var Tooltip = {
followMouse: true,
offX: 8,
offY: 12,
tipID: "tipDiv",
showDelay: 100,
hideDelay: 200,

ready:false, timer:null, tip:null,

init: function() {
if ( document.createElement && document.body && typeof
document.body.appendChild != "undefined" ) {
if ( !document.getElementById(this.tipID) ) {
var el = document.createElement("DIV");
el.id = this.tipID; document.body.appendChild(el);
}
this.ready = true;
}
},

show: function(e, msg) {
if (this.timer) { clearTimeout(this.timer); this.timer = 0; }
this.tip = document.getElementById( this.tipID );
if (this.followMouse) // set up mousemove
dw_event.add( document, "mousemove", this.trackMouse, true );
this.writeTip(""); // for mac ie
this.writeTip(msg);
viewport.getAll();
this.positionTip(e);
this.timer = setTimeout("Tooltip.toggleVis('" + this.tipID + "', 'visible')", this.showDelay);
},

writeTip: function(msg) {
if ( this.tip && typeof this.tip.innerHTML != "undefined" ) this.tip.innerHTML = msg;
},

positionTip: function(e) {
if ( this.tip && this.tip.style ) {
// put e.pageX/Y first! (for Safari)
var x = e.pageX? e.pageX: e.clientX + viewport.scrollX;
var y = e.pageY? e.pageY: e.clientY + viewport.scrollY;

if ( x + this.tip.offsetWidth + this.offX > viewport.width + viewport.scrollX ) {
x = x - this.tip.offsetWidth - this.offX;
if ( x < 0 ) x = 0;
} else x = x + this.offX;

if ( y + this.tip.offsetHeight + this.offY > viewport.height + viewport.scrollY ) {
y = y - this.tip.offsetHeight - this.offY;
if ( y < viewport.scrollY ) y = viewport.height + viewport.scrollY - this.tip.offsetHeight;
} else y = y + this.offY;

this.tip.style.left = x + "px"; this.tip.style.top = y + "px";
}
},

hide: function() {
if (this.timer) { clearTimeout(this.timer); this.timer = 0; }
this.timer = setTimeout("Tooltip.toggleVis('" + this.tipID + "', 'hidden')", this.hideDelay);
if (this.followMouse) // release mousemove
dw_event.remove( document, "mousemove", this.trackMouse, true );
this.tip = null;
},

toggleVis: function(id, vis) { // to check for el, prevent (rare) errors
var el = document.getElementById(id);
if (el) el.style.visibility = vis;
},

trackMouse: function(e) {
e = dw_event.DOMit(e);
Tooltip.positionTip(e);
}

}

Tooltip.init();

时间: 2024-08-03 05:52:20

CSS+js实现的一个优秀的超链接鼠标悬停提示的相关文章

一个优秀的超链接鼠标悬停提示CSS+JS

css|js|链接     超链接,一般的做法是给一个title属性,这样用户的鼠标悬停在超链接上的时候,它会显示title的内容.但是,你是否厌倦了千篇一律的鼠标悬停效果呢?       当然,也有这方面很炫的代码,但是才跨浏览器方面功夫还是不够,呵呵.我遇到一个不错的css,在IE和Firefox下浏览一样的效果.       下图是实际运行的效果: 代码如下: /******************************************************   dw_view

js实现动画特效的文字链接鼠标悬停提示的方法

 这篇文章主要介绍了js实现动画特效的文字链接鼠标悬停提示的方法,实例分析了javascript操作css的技巧,具有一定参考借鉴价值,需要的朋友可以参考下     本文实例讲述了js实现动画特效的文字链接鼠标悬停提示的方法.分享给大家供大家参考.具体实现方法如下:   代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD

纯CSS实现鼠标悬停提示的方法

本文实例讲述了纯CSS实现鼠标悬停提示的方法.分享给大家供大家参考.具体分析如下:   这是一款比较漂亮的鼠标悬停提示效果,用纯CSS代码实现,鼠标放到图片上会显示一个层,也就是悬停时的提示,在这个提示框内你还可以加入图片或是一个列表,这就靠你的发挥了,提示框的背景颜色和文字颜色你都可以自己调. 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/

js 文字超出长度用省略号代替,鼠标悬停并以悬浮框显示实例_javascript技巧

题目中问题一拆为二: 1.文字在超出长度时,如何实现用省略号代替? 2.超长长度的文字在省略显示后,如何在鼠标悬停时,以悬浮框的形式显示出全部信息? 文字在超出长度时,如何实现用省略号代替? 用CSS实现超长字段用省略号表示的方法:所有浏览器兼容! html代码如下: <div style="width:150px;overflow:hidden; white-space:nowrap; text-overflow:ellipsis"> 用CSS实现超长字段被省略的简单方法

纯css+js写的一个简单的tab标签页带样式_javascript技巧

最近经常要用tab标签页,所以写了一个简单的,以后用的话直接拷贝一个,稍微改改就OK了. 先看效果图:  接下来看下代码怎么写的吧: 一.sp文件easytab.jsp 复制代码 代码如下: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String b

CSS或者JS实现鼠标悬停显示另一元素_javascript技巧

想达到鼠标悬停到元素a上,显示另一个元素b,可以通过css实现也可以通过js实现. js: 写两个函数:mouseenter,mouseleave,例如:其中 $("#a").mouseenter(function() { $("#b").show("normal"); }); $("#a").mouseleave(function() { $("#b").hide("normal");

css实现鼠标悬停时滑出层提示的方法

 本文实例讲述了css实现鼠标悬停时滑出层提示的方法.分享给大家供大家参考.具体分析如下: 这是一个简单的鼠标悬停提示特效,类似于alt标签,不过这一种是用纯CSS实现,扩展性好,而且在提示的层里可以加入图片或其它布局,这个要根据你的需要了.   代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-tran

js-如何用CSS或者JS隐藏这样一个标签,&amp;amp;lt;label for=&amp;amp;quot;notebutton&amp;amp;quot;&amp;amp;gt;VJSP批注模式&amp;amp;lt;/label&amp;amp;gt;

问题描述 如何用CSS或者JS隐藏这样一个标签,<label for="notebutton">VJSP批注模式</label> 完整形式 VJSP批注模式 解决方案 没人知道吗,真心求教啊

IE6下js通过css隐藏select的一个bug_表单特效

今天遇到一个问题, 当隐藏表格行 Tr 时 $id("tr_" + id + "_1").style.setAttribute('cssText',"display:none;");, 表格行 Tr 里面的 select 在 IE6 中隐藏不了,还是会显示在页面当中.想单独设置 select 的样式为隐藏 $id("new_attpm_id2_" + id).style.setAttribute('cssText',"