|
<SPAN style="FONT-SIZE: 12px" twffan="done">超链接,一般的做法是给一个title属性,这样用户的鼠标悬停在超链接上的时候,它会显示title的内容。但是,你是否厌倦了千篇一律的鼠标悬停效果呢? <BR> 当然,也有这方面很炫的代码,但是才跨浏览器方面功夫还是不够,呵呵。我遇到一个不错的css,在IE和Firefox下浏览一样的效果。<BR><BR>实际的效果大家可以参考:校园招聘一网打尽 <A href="http://www.xyzp.net/index.html" target=_blank><FONT color=#003366>http://www.xyzp.net/index.html</FONT></A><BR><BR>代码如下:<BR><BR>/*************************************************************************<BR><BR> dw_viewport.js<BR> version date Nov 2003<BR> <BR> This code is from Dynamic Web Coding <BR> at <A href="http://www.dyn-web.com/" target=_blank><FONT color=#003366>http://www.dyn-web.com/</FONT></A><BR> Copyright 2003 by Sharon Paine <BR> See Terms of Use at <A href="http://www.dyn-web.com/bus/terms.html" target=_blank><FONT color=#003366>http://www.dyn-web.com/bus/terms.html</FONT></A><BR> regarding conditions under which you may use this code.<BR> This notice must be retained in the code as is!<BR><BR>*************************************************************************/ <BR> <BR>var viewport = {<BR> getWinWidth: function () {<BR> this.width = 0;<BR> if (window.innerWidth) this.width = window.innerWidth - 18;<BR> else if (document.documentElement && document.documentElement.clientWidth) <BR> this.width = document.documentElement.clientWidth;<BR> else if (document.body && document.body.clientWidth) <BR> this.width = document.body.clientWidth;<BR> },<BR> <BR> getWinHeight: function () {<BR> this.height = 0;<BR> if (window.innerHeight) this.height = window.innerHeight - 18;<BR> else if (document.documentElement && document.documentElement.clientHeight) <BR> this.height = document.documentElement.clientHeight;<BR> else if (document.body && document.body.clientHeight) <BR> this.height = document.body.clientHeight;<BR> },<BR> <BR> getScrollX: function () {<BR> this.scrollX = 0;<BR> if (typeof window.pageXOffset == "number") this.scrollX = window.pageXOffset;<BR> else if (document.documentElement && document.documentElement.scrollLeft)<BR> this.scrollX = document.documentElement.scrollLeft;<BR> else if (document.body && document.body.scrollLeft) <BR> this.scrollX = document.body.scrollLeft; <BR> else if (window.scrollX) this.scrollX = window.scrollX;<BR> },<BR> <BR> getScrollY: function () {<BR> this.scrollY = 0; <BR> if (typeof window.pageYOffset == "number") this.scrollY = window.pageYOffset;<BR> else if (document.documentElement && document.documentElement.scrollTop)<BR> this.scrollY = document.documentElement.scrollTop;<BR> else if (document.body && document.body.scrollTop) <BR> this.scrollY = document.body.scrollTop; <BR> else if (window.scrollY) this.scrollY = window.scrollY;<BR> },<BR> <BR> getAll: function () {<BR> this.getWinWidth(); this.getWinHeight();<BR> this.getScrollX(); this.getScrollY();<BR> }<BR> <BR>}<BR><BR>/*************************************************************************<BR> dw_event.js (version date Feb 2004)<BR> <BR> This code is from Dynamic Web Coding at <A href="http://www.dyn-web.com/" target=_blank><FONT color=#003366>http://www.dyn-web.com/</FONT></A><BR> See Terms of Use at <A href="http://www.dyn-web.com/bus/terms.html" target=_blank><FONT color=#003366>http://www.dyn-web.com/bus/terms.html</FONT></A><BR> regarding conditions under which you may use this code.<BR> This notice must be retained in the code as is!<BR>*************************************************************************/<BR><BR>var dw_event = {<BR> <BR> add: function(obj, etype, fp, cap) {<BR> cap = cap || false;<BR> if (obj.addEventListener) obj.addEventListener(etype, fp, cap);<BR> else if (obj.attachEvent) obj.attachEvent("on" + etype, fp);<BR> }, <BR><BR> remove: function(obj, etype, fp, cap) {<BR> cap = cap || false;<BR> if (obj.removeEventListener) obj.removeEventListener(etype, fp, cap);<BR> else if (obj.detachEvent) obj.detachEvent("on" + etype, fp);<BR> }, <BR><BR> DOMit: function(e) { <BR> e = e? e: window.event;<BR> e.tgt = e.srcElement? e.srcElement: e.target;<BR> <BR> if (!e.preventDefault) e.preventDefault = function () { return false; }<BR> if (!e.stopPropagation) e.stopPropagation = function () <BR>{ if (window.event) window.event.cancelBubble = true; }<BR> <BR> return e;<BR> }<BR> <BR>}<BR>/*************************************************************************<BR> dw_tooltip.js requires: dw_event.js and dw_viewport.js<BR> version date: March 14, 2005 <BR> (minor changes in position algorithm and timer mechanism)<BR> <BR> This code is from Dynamic Web Coding at dyn-web.com<BR> Copyright 2003-5 by Sharon Paine <BR> See Terms of Use at <A href="http://www.dyn-web.com/bus/terms.html" target=_blank><FONT color=#003366>www.dyn-web.com/bus/terms.html</FONT></A><BR> regarding conditions under which you may use this code.<BR> This notice must be retained in the code as is!<BR>*************************************************************************/<BR>var Tooltip = {<BR> followMouse: true,<BR> offX: 8,<BR> offY: 12,<BR> tipID: "tipDiv",<BR> showDelay: 100,<BR> hideDelay: 200,<BR> <BR> ready:false, timer:null, tip:null, <BR> <BR> init: function() { <BR> if ( document.createElement && document.body && typeof <BR>document.body.appendChild != "undefined" ) {<BR> if ( !document.getElementById(this.tipID) ) {<BR> var el = document.createElement("DIV");<BR> el.id = this.tipID; document.body.appendChild(el);<BR> }<BR> this.ready = true;<BR> }<BR> },<BR> <BR> show: function(e, msg) {<BR> if (this.timer) { clearTimeout(this.timer); this.timer = 0; }<BR> this.tip = document.getElementById( this.tipID );<BR> if (this.followMouse) // set up mousemove <BR> dw_event.add( document, "mousemove", this.trackMouse, true );<BR> this.writeTip(""); // for mac ie<BR> this.writeTip(msg);<BR> viewport.getAll();<BR> this.positionTip(e);<BR> this.timer = setTimeout("Tooltip.toggleVis('" + this.tipID + "', 'visible')", this.showDelay);<BR> },<BR> <BR> writeTip: function(msg) {<BR> if ( this.tip && typeof this.tip.innerHTML != "undefined" ) this.tip.innerHTML = msg;<BR> },<BR> <BR> positionTip: function(e) {<BR> if ( this.tip && this.tip.style ) {<BR> // put e.pageX/Y first! (for Safari)<BR> var x = e.pageX? e.pageX: e.clientX + viewport.scrollX;<BR> var y = e.pageY? e.pageY: e.clientY + viewport.scrollY;<BR> <BR> if ( x + this.tip.offsetWidth + this.offX > viewport.width + viewport.scrollX ) {<BR> x = x - this.tip.offsetWidth - this.offX;<BR> if ( x < 0 ) x = 0;<BR> } else x = x + this.offX;<BR> <BR> if ( y + this.tip.offsetHeight + this.offY > viewport.height + viewport.scrollY ) {<BR> y = y - this.tip.offsetHeight - this.offY;<BR> if ( y < viewport.scrollY ) y = viewport.height + viewport.scrollY - this.tip.offsetHeight;<BR> } else y = y + this.offY;<BR> <BR> this.tip.style.left = x + "px"; this.tip.style.top = y + "px";<BR> }<BR> },<BR> <BR> hide: function() {<BR> if (this.timer) { clearTimeout(this.timer); this.timer = 0; }<BR> this.timer = setTimeout("Tooltip.toggleVis('" + this.tipID + "', 'hidden')", this.hideDelay);<BR> if (this.followMouse) // release mousemove<BR> dw_event.remove( document, "mousemove", this.trackMouse, true );<BR> this.tip = null; <BR> },<BR><BR> toggleVis: function(id, vis) { // to check for el, prevent (rare) errors<BR> var el = document.getElementById(id);<BR> if (el) el.style.visibility = vis;<BR> },<BR> <BR> trackMouse: function(e) {<BR> e = dw_event.DOMit(e);<BR> Tooltip.positionTip(e);<BR> }<BR> <BR>}<BR><BR>Tooltip.init();</SPAN> <BR> |
|