| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 597 人关注过本帖
标题:很棒的ALT,跟随鼠标移动。但是有点问题。
只看楼主 加入收藏
dryfish
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-7-25
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
很棒的ALT,跟随鼠标移动。但是有点问题。
代码如下,有点问题,只要拉动滚动条,ALT内容就会错位,很严重~~这个情况应该怎么处理呢,请高手指教。不胜感激。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>自定义Alt-www.-www.
</head>
<body>
<span alt="好孩子^O^">过来</span><br><br>
<span alt="好孩子^O^" altbg="red" altcolor=yellow altborder="yellow">过来</span><br><br>
<span alt="好孩子^O^" altbg="#F7F7F7" altcolor="#999999" altborder="#CCCCCC">过来</span><br><br>
<span alt="好孩子^O^" altbg="green" altcolor=yellow altborder="darkgreen">过来</span><br><br>
<span alt="好孩子^O^" altbg="#000000" altcolor="#FFFFFF" altborder="#000000">过来</span>
<span alt="好孩子^O^">过来</span><br><br>
<span alt="好孩子^O^" altbg="red" altcolor=yellow altborder="yellow">过来</span><br><br>
<span alt="好孩子^O^" altbg="#F7F7F7" altcolor="#999999" altborder="#CCCCCC">过来</span><br><br>
<span alt="好孩子^O^" altbg="green" altcolor=yellow altborder="darkgreen">过来</span><br><br>
<span alt="好孩子^O^" altbg="#000000" altcolor="#FFFFFF" altborder="#000000">过来</span> <span alt="好孩子^O^">过来</span><br><br>
<span alt="好孩子^O^" altbg="red" altcolor=yellow altborder="yellow">过来</span><br><br>
<span alt="好孩子^O^" altbg="#F7F7F7" altcolor="#999999" altborder="#CCCCCC">过来</span><br><br>
<span alt="好孩子^O^" altbg="green" altcolor=yellow altborder="darkgreen">过来</span><br><br>
<span alt="好孩子^O^" altbg="#000000" altcolor="#FFFFFF" altborder="#000000">过来</span>
<span alt="好孩子^O^">过来</span><br><br>
<span alt="好孩子^O^" altbg="red" altcolor=yellow altborder="yellow">过来</span><br><br>
<span alt="好孩子^O^" altbg="#F7F7F7" altcolor="#999999" altborder="#CCCCCC">过来</span><br><br>
<span alt="好孩子^O^" altbg="green" altcolor=yellow altborder="darkgreen">过来</span><br><br>
<span alt="好孩子^O^" altbg="#000000" altcolor="#FFFFFF" altborder="#000000">过来</span>
<span alt="好孩子^O^">过来</span><br><br>
<span alt="好孩子^O^" altbg="red" altcolor=yellow altborder="yellow">过来</span><br><br>
<span alt="好孩子^O^" altbg="#F7F7F7" altcolor="#999999" altborder="#CCCCCC">过来</span><br><br>
<span alt="好孩子^O^" altbg="green" altcolor=yellow altborder="darkgreen">过来</span><br><br>
<span alt="好孩子^O^" altbg="#000000" altcolor="#FFFFFF" altborder="#000000">过来</span>
<span alt="好孩子^O^">过来</span><br><br>
<span alt="好孩子^O^" altbg="red" altcolor=yellow altborder="yellow">过来</span><br><br>
<span alt="好孩子^O^" altbg="#F7F7F7" altcolor="#999999" altborder="#CCCCCC">过来</span><br><br>
<span alt="好孩子^O^" altbg="green" altcolor=yellow altborder="darkgreen">过来</span><br><br>
<span alt="好孩子^O^" altbg="#000000" altcolor="#FFFFFF" altborder="#000000">过来</span>
<span alt="好孩子^O^">过来</span><br><br>
<span alt="好孩子^O^" altbg="red" altcolor=yellow altborder="yellow">过来</span><br><br>
<span alt="好孩子^O^" altbg="#F7F7F7" altcolor="#999999" altborder="#CCCCCC">过来</span><br><br>
<span alt="好孩子^O^" altbg="green" altcolor=yellow altborder="darkgreen">过来</span><br><br>
<span alt="好孩子^O^" altbg="#000000" altcolor="#FFFFFF" altborder="#000000">过来</span>
<div style="display:none;border:1px solid #000000;background-color:#FFFFCC;font-size:12px;position:absolute;padding:2;" id=altlayer></div>
<script>
document.body.onmousemove=quickalt;
document.body.onmouseover=getalt;
document.body.onmouseout=restorealt;
var tempalt='';

function getalt()
{
if(event.srcElement.alt && (event.srcElement.alt!='' || (event.srcElement.alt=='' && tempalt!='')))
{
altlayer.style.left=event.x;
altlayer.style.top=event.y+20;
altlayer.style.display='';
tempalt=event.srcElement.alt;
tempbg=event.srcElement.altbg;
tempcolor=event.srcElement.altcolor;
tempborder=event.srcElement.altborder;
event.srcElement.alt='';
altlayer.innerText=tempalt;
if (typeof(tempbg)!="undefined"){altlayer.style.background=tempbg}else{altlayer.style.background="#FFFFCC"}
if (typeof(tempcolor)!="undefined"){altlayer.style.color=tempcolor}else{altlayer.style.color=tempcolor="#000000"}
if (typeof(tempborder)!="undefined"){altlayer.style.border='1px solid '+tempborder;}else{altlayer.style.border='1px solid #000000';}
}
}
function quickalt()
{
if(altlayer.style.display=='')
{
altlayer.style.left=event.x;
altlayer.style.top=event.y+10;
}
}

function restorealt()
{
event.srcElement.alt=tempalt;
tempalt='';
altlayer.style.display='none';
}
</script>
</body>
</html>

<div style="position: absolute; top: 10; right: 10; width: 148; height: 18;cursor:hand">
<input type="button" name="Button" value="查看源代码" onClick= 'window.location = "view-source:" + window.location.href'></div>
搜索更多相关主题的帖子: ALT 很棒 跟随 鼠标 
2009-07-25 15:30
dryfish
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-7-25
收藏
得分:0 
正确答案:将event.x和event.y换成
(window.event.x   +   document.body.scrollLeft)和
(window.event.y   +   document.body.scrollTop)
2009-07-25 16:03
pgj999
Rank: 2
等 级:论坛游民
帖 子:11
专家分:93
注 册:2009-7-28
收藏
得分:0 
二楼正解,加上document.body.scrollLeft,让其支持鼠标滚动条滚动功能就可以了。
2009-07-29 10:56
快速回复:很棒的ALT,跟随鼠标移动。但是有点问题。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031324 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved