当前位置: 电脑软硬件应用网 > 设计学院 > 网页特效 > 正文
鼠标在文本上移动时层的显示与消失
鼠标在文本上移动时层的显示与消失
2005-12-30 18:54:02  文/45IT收集   出处:电脑软硬件应用网   

花了两天的时间才把这个简单的东西给做出来。本来早就想做这个东西的,但是由于......(跟老板后面做事,当然空闲的时间就少了,唉,实在不好意思,因为自己不才,所以找了个借口)。刚好现在公司又让我做个房产管理系统,要用这样的一个方法了,所以才狠下心来非把这个做出来不可。我认为这个例子非常实用(个人看法),而且好多大型网站上都有这种应用。今天写下来和各位朋友一起分享。以下就是我的所有代码,有不妥之处还请各位高人指教,在此先谢了。 
  把这里的所有代码都放在<body>与</body>之间即可 
<script language=javascript> 
<!-- 
function hiddiv() 

document.all.ab.style.display="none" 

function showdiv() 

document.all.ab.style.display="" 
document.all.ab.style.left=window.event.clientX+15 
document.all.ab.style.top=window.event.clientY 

//--> 

</script> 
<div id=ab style="position: absolute; width: 126; height: 27; background-color: orange; display: none; left: 11; top: 36">地址:园区星海街东侧<br>电话:0512-65103588-206</div> 

<table border="0" cellpadding="0" cellspacing="0" width="600"> 
<tr> 
<td width="150"><a href="#" onmouseout=hiddiv(); onmousemove=showdiv();>发现之旅</a></td> 
</tr> 
</table> 

  当然了这里的功能比较简单,没有对浏览器类型进行判断,本人不才,就把这个问题留给各位了,欢迎每一位朋友来修改这个问题。 
  在这里还有一个问题就是如果文本不止一个、定义的层也就不止一个。如果还用这样的方法就会出错,我对这个问题研究了一下,用下面的这个方法就可以解决了。 
<script language=javascript> 
<!-- 
function hiddiv(blah) 

blah.style.display="none" 

function showdiv(blah) 

blah.style.display="" 
blah.style.left=window.event.clientX+15 
blah.style.top=window.event.clientY 

//--> 

</script> 
<div id=ab style="position: absolute; width: 126; height: 27; background-color: orange; display: none; left: 11; top: 36">地址:园区星海街东侧<br>电话:0512-65103588-20611</div> 

<div id=cd style="position: absolute; width: 126; height: 27; background-color: orange; display: none; left: 11; top: 36">地址:新区明星街南侧<br>电话:0512-65103588-20622</div> 

<table border="0" cellpadding="0" cellspacing="0" width="600"> 
<tr> 
<td width="150"><a href="#" onmouseout=hiddiv(ab); onmousemove=showdiv(ab);>发现之旅</a></td> 
</tr> 
<tr> 
<td width="150"><a href="#" onmouseout=hiddiv(cd); onmousemove=showdiv(cd);>和风景苑</a></td> 
</tr> 
</table> 

  如果有更多的文本和层的话以此类推即可。 
  在这里有几点要说明的就是: 
  1、showdiv中带参数时再用document.all.ab.style.display=""就不适用了,关于这点朋友们可以参考有关书籍 
  2、onmouseover与onmousemove的区别是:当鼠标移过当前对象时就产生了onmouseover事件,当鼠标在当前对象上移动时就产生了onmousemove事件,只要是在对象上移动而且没有移出对象的,就是onmousemove事件。我当前就是因为这个onmouseover事件惹的祸要不早就搞定了。今天写出来让朋友们也能注意这一点。 
  3、如果朋友们有更好的方法或有不明白的地方我们可以一起探讨。 
  4、有需要的朋友可以直接拿去用,本人保留版权

  • 上一篇文章:

  • 下一篇文章:
  • 最新热点 最新推荐 相关文章
    网页特效代码:仿京东的商品分类导航…
    不能屏蔽的网页右下角窗口特效
    装载页面进度条代码
    链接特效之js做引用文章链接代码
    左右移动转换文字特效HTML代码解析
    网页页面实现自动刷新的3种代码
    网页特效代码:纯css下拉菜单列表
    JS特效代码:实现间歇无缝文字滚动特…
    文字滚动特效(兼容多浏览器)
    网页特效代码:JavaScript显示系统时…
    关于45IT | About 45IT | 联系方式 | 版权声明 | 网站导航 |

    Copyright © 2003-2011 45IT. All Rights Reserved 浙ICP备09049068号