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

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 nbpig 的 blog

  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 ) {
      &nbs

本文关键:一个优秀的超链接鼠标悬停提示CSS+js
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top