找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1096|回复: 0

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

[复制链接]

2074

主题

6459

回帖

45万

积分

管理员

夏天啊·····

积分
452930

王子的皇冠大富翁大众宠儿外太空使者社区居民

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

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Enjoy Game

GMT+8, 2024-12-27 13:50 , Processed in 0.089675 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表