当前位置:首页>编程日记>正文

鼠标滑过某一个图标时,提示讯息

现在的系统使用这样的方法:(tips.js)
//
// Browser Detection
//
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;

// Generic Layer Object Functions

// Make an object visible
function showObject(obj)
{
        if (NS4) obj.visibility = "show";
        else if (IE4plus) obj.visibility = "visible";
}

// Hides an object
function hideObject(obj)
{
        if (NS4) obj.visibility = "hide";
        else if (IE4plus) obj.visibility = "hidden";
}

// Move a layer
function moveTo(obj,xL,yL)
{
        obj.left = xL;
        obj.top = yL;
}


//
// MouseTip Methods
//

function MouseTip_ShowNew()
{
 this.WriteLayer();
 this.Show();
}

function MouseTip_Hide()
{
 if ( (NS4) || (IE4plus) )
 {
  this.snow = 0;
  hideObject(this.over);
 }
}

function MouseTip_Show()
{
 if ( (NS4) || (IE4plus) )
 {
  if (this.snow == 0)  
  {
   if (this.dir == 3)
   { // Center
    moveTo(this.over,MouseTip.offsetX,MouseTip.offsetY);
   }
   if (this.dir == 2)
   { // Center
    moveTo(this.over,this.x+MouseTip.offsetX-(MouseTip.width/2),this.y+MouseTip.offsetY);
   }
   if (this.dir == 1)
   { // Right
    moveTo(this.over,this.x+MouseTip.offsetX,this.y+MouseTip.offsetY);
   }
   if (this.dir == 0)
   { // Left
    moveTo(this.over,this.x-MouseTip.offsetX-MouseTip.width,this.y+MouseTip.offsetY);
   }
   showObject(this.over);
   this.snow = 1;
  }
 }
}


// Writes to a layer
function MouseTip_WriteLayer()
{
        if (NS4)
        {
                var lyr = eval(MouseTip.divPath).document;
                lyr.write(this.txt);
                lyr.close();
        }
        else if (IE4plus)
   document.all["overDiv"].innerHTML = this.txt;
}

function MouseTip_AddTip(type, tipTitle, tipText)
{
 var tip = new Object();
 tip.type = type;
 tip.title = tipTitle;
 tip.text = tipText;
 MouseTip.tips[MouseTip.tips.length] = tip;
}

function MouseTip_GetTip(type)
{
 var tip = null;
 
 for (i=0; i < MouseTip.tips.length; i++)
 {
  if (MouseTip.tips[i].type==type)
  {
   tip = MouseTip.tips[i];
   break;
  }
 }
 return tip;
}

function MouseTip(type,dir,x,y)
{
 this.x = x;
 this.y = y;
 this.snow = 0;
 this.dir = dir;
 this.over = null;
 
 this.ShowNew = MouseTip_ShowNew;
 this.Hide = MouseTip_Hide;
 this.Show = MouseTip_Show;
 this.WriteLayer = MouseTip_WriteLayer;

 if ( (NS4) || (IE4plus) )
 {
  if (NS4) this.over = eval(MouseTip.divPath);
  if (IE4plus) this.over = document.all["overDiv"].style;
 }

 var tip = MouseTip.GetTip(type);
 
 this.txt = '<TABLE WIDTH=' + MouseTip.width + ' BORDER=0 CELLPADDING=' + MouseTip.borderWidth +
  ' CELLSPACING=0 BGCOLOR="pink"><TD>' +  tip.text + '</TD></TABLE>';
 
}


MouseTip.current = null;
MouseTip.tips = new Array();
MouseTip.bgColor = "#CC0000";
MouseTip.borderColor = "#42316B";
MouseTip.width = 200
MouseTip.borderWidth = 1;
MouseTip.offsetX = 10;
MouseTip.offsetY = 0;
MouseTip.divPath = "document.overDiv";

MouseTip.AddTip = MouseTip_AddTip;
MouseTip.GetTip = MouseTip_GetTip;


function ShowMouseTip(obj,e,type, pos)
{
 if ( (NS4) || (IE4plus) )
 {
  if(! pos) pos = 1;
  var x = 0;
  var y = 0;
  if (NS4) {x=e.pageX; y=e.pageY;}
  if (IE4plus) {x=e.clientX+document.body.scrollLeft; y=e.clientY+document.body.scrollTop;}

  MouseTip.current = new MouseTip(type,pos,x,y);
  MouseTip.current.ShowNew();
 }
}

function HideMouseTip()
{
 if ( (NS4) || (IE4plus) )
 {
  if (MouseTip.current)
   MouseTip.current.Hide();
 }
}
在调用页面:
<script language="javascript" src="js/tips.js" >

MouseTip.AddTip("MenuLogOut", "", "<%=bundle1.getProperty("top_logout")%>");
MouseTip.AddTip("MenuContact", "", "<%=bundle1.getProperty("top_contact")%>");
MouseTip.AddTip("MenuHelp", "", "<%=bundle1.getProperty("top_help")%>");
MouseTip.AddTip("MenuMyProfile", "", "<%=bundle1.getProperty("top_profile")%>");
MouseTip.AddTip("Menuhk", "", "<%=bundle1.getProperty("top_homepage")%>");

  <td width="20%" align="right">
 <a href="userProfile.jsp" target="text" onMouseOver="ShowMouseTip(this, event, 'MenuMyProfile', 3);" onMouseOut="HideMouseTip()">
  <img width="32" height="32" border="0" src="images/myprofile.png" ></a>
 <a href="contact.jsp" target="text" onMouseOver="ShowMouseTip(this, event, 'MenuContact', 3)" onMouseOut="HideMouseTip()">
  <img width="32" height="32" border="0" src="images/contact.png" ></a>
 <a href="help/help.htm"  target="text" onMouseOver="ShowMouseTip(this, event, 'MenuHelp', 3)" onMouseOut="HideMouseTip()" >
  <img width="32" height="32" src="images/help.png" border="0"  ></a>
 <a href="javascript:top.window.close()" target="_top" onMouseOver="ShowMouseTip(this, event, 'MenuLogOut', 3)" onMouseOut="HideMouseTip()">
  <img width="32" height="32" src="images/logout.png" border="0"></a>
 <a href=http://www.yahoo.com.cn target="text" onMouseOver="ShowMouseTip(this, event, 'Menuhk', 3)" onMouseOut="HideMouseTip()">
  <img border="0" src="images/logo.gif"width="22.4" height="27.3" ></a></td>

在IE下面可以实现提示讯息这样的功能,可是在FireFox下面则不行.
所以就要使用另外一种方法:
<a href="userProfile.jsp" target="text" onMouseOver="ShowMouseTip(this, event, 'MenuMyProfile', 3);" onMouseOut="HideMouseTip()">
  <img width="32" height="32" border="0" src="images/myprofile.png" title="<%=bundle1.getProperty("top_profile")%>" alt="<%=bundle1.getProperty("top_profile")%>"></a>
这样就可以在不同浏览器下面都能实现了!
但是切记,一定要加上title和alt,如果仅仅有alt的话,在FireFox下面也是无法提示讯息的.
这个我找了好久,终于把问题解决了!
js文件和jsp文件在下面附件中:可以参考
事例文件


http://www.coolblog.cn/news/64021236fbc98509.html

相关文章:

  • asp多表查询并显示_SpringBoot系列(五):SpringBoot整合Mybatis实现多表关联查询
  • s7day2学习记录
  • 【求锤得锤的故事】Redis锁从面试连环炮聊到神仙打架。
  • 矿Spring入门Demo
  • 拼音怎么写_老师:不会写的字用圈代替,看到孩子试卷,网友:人才
  • Linux 实时流量监测(iptraf中文图解)
  • Win10 + Python + GPU版MXNet + VS2015 + RTools + R配置
  • 美颜
  • shell访问php文件夹,Shell获取某目录下所有文件夹的名称
  • 如何优雅的实现 Spring Boot 接口参数加密解密?
  • LeCun亲授的深度学习入门课:从飞行器的发明到卷积神经网络
  • Mac原生Terminal快速登录ssh
  • java受保护的数据与_Javascript类定义语法,私有成员、受保护成员、静态成员等介绍...
  • mysql commit 机制_1024MySQL事物提交机制
  • 支撑微博千亿调用的轻量级RPC框架:Motan
  • jquery 使用小技巧
  • 2019-9
  • 法拉利虚拟学院2010 服务器,法拉利虚拟学院2010
  • vscode pylint 错误_将实际未错误的py库添加到pylint白名单
  • 科学计算工具NumPy(3):ndarray的元素处理
  • 工程师在工作电脑存 64G 不雅文件,被公司开除后索赔 41 万,结果…
  • linux批量创建用户和密码
  • newinsets用法java_Java XYPlot.setInsets方法代碼示例
  • js常用阻止冒泡事件
  • 气泡图在开源监控工具中的应用效果
  • 各类型土地利用图例_划重点!国土空间总体规划——土地利用
  • php 启动服务器监听
  • dubbo简单示例
  • 【设计模式】 模式PK:策略模式VS状态模式
  • [iptables]Redhat 7.2下使用iptables实现NAT
  • Ubuntu13.10:[3]如何开启SSH SERVER服务
  • CSS小技巧——CSS滚动条美化
  • JS实现-页面数据无限加载
  • 阿里巴巴分布式服务框架 Dubbo
  • 最新DOS大全
  • Django View(视图系统)
  • 阿里大鱼.net core 发送短信
  • 程序员入错行怎么办?
  • 两张超级大表join优化
  • 第九天函数
  • Linux软件安装-----apache安装
  • HDU 5988 最小费用流
  • Sorenson Capital:值得投资的 5 种 AI 技术
  • 《看透springmvc源码分析与实践》读书笔记一
  • 正式开课!如何学习相机模型与标定?(单目+双目+鱼眼+深度相机)
  • Arm芯片的新革命在缓缓上演
  • nagios自写插件—check_file
  • python3 错误 Max retries exceeded with url 解决方法
  • 行为模式之Template Method模式
  • 通过Spark进行ALS离线和Stream实时推荐