奇怪的JS跟随层问题

yalan 2007-11-13 10:32:30
修改了梅花雪老板的树,当鼠标移动到树的节点上时出现一个跟随层提示该节点的信息(该信息为树的hint字段)。
树初始化后跟随层能够正常显示,如果展开树浏览器会出现滚动条,这时如果向下拉滚动条,再将鼠标移动到刚才没有在浏览器中显示的节点时,会发现跟随层跑到上面去了。显然跟随层还是以鼠标没有移动以前的坐标来显示层的。
如果节点位置越靠下,那么跟随层距离鼠标越远。
请问这个问题如何解决呢?谢谢各位前辈。下面附跟随层的主要js代码:
// 主背景色(大区域)
if (typeof fcolor == 'undefined') { var fcolor = "#F2F2F2";}
// Border的颜色和标题栏的颜色;
if (typeof backcolor == 'undefined') { var backcolor = "#cccccc";}
// 文字的颜色
// 通常是比较深的颜色;
if (typeof textcolor == 'undefined') { var textcolor = "#000000";}
// 标题的颜色
if (typeof capcolor == 'undefined') { var capcolor = "blue";}
// "Close"的颜色
// 通常是明快的颜色;
if (typeof closecolor == 'undefined') { var closecolor = "yellow";}
// 弹出的窗口的宽度;
// 100-300 pixels 合适
if (typeof width == 'undefined') { var width = "200";}
// 边缘的宽度,象素。
// 1-3 pixels 合适
if (typeof border == 'undefined') { var border = "1";}
// 弹出窗口位于鼠标左侧或者右侧的距离,象素。
// 3-12合适
if (typeof offsetx == 'undefined') { var offsetx = 10;}
// 弹出窗口位于鼠标下方的距离;
// 3-12 合适
if (typeof offsety == 'undefined') { var offsety = 10;}
// 设置结束
//////////
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
// Microsoft Stupidity Check.
if (ie4) {
if (navigator.userAgent.indexOf('MSIE 5')>0) {
ie5 = true;
} else {
ie5 = false; }
} else {
ie5 = false;
}
var x = 0;
var y = 0;
var snow = 0;
var sw = 0;
var cnt = 0;
var dir = 1;
var tr = 1;
if ( (ns4) || (ie4) ) {
if (ns4) over = document.overDiv
if (ie4) over = overDiv.style
document.onmousemove = mouseMove
if (ns4) document.captureEvents(Event.MOUSEMOVE)
}
// 以下是页面中使用的公共函数;
// Simple popup right
function drs(text) {
dts(1,text);
}
// Caption popup right
function drc(text, title) {
dtc(1,text,title);
}
// Sticky caption right
function src(text,title) {
stc(1,text,title);
}
// Simple popup left
function dls(text) {
dts(0,text);
}
// Caption popup left
function dlc(text, title) {
dtc(0,text,title);
}
// Sticky caption left
function slc(text,title) {
stc(0,text,title);
}
// Simple popup center
function dcs(text) {
dts(2,text);
}
// Caption popup center
function dcc(text, title) {
dtc(2,text,title);
}
// Sticky caption center
function scc(text,title) {
stc(2,text,title);
}
// Clears popups if appropriate
function nd() {
if ( cnt >= 1 ) { sw = 0 };
if ( (ns4) || (ie4) ) {
if ( sw == 0 ) {
snow = 0;
hideObject(over);
} else {
cnt++;
}
}
}
// 非公共函数,被其它的函数调用;
// Simple popup
function dts(d,text) {
txt = "<TABLE WIDTH="+width+" BORDER=0 CELLPADDING="+border+" CELLSPACING=0 BGCOLOR=\""+backcolor+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=\""+fcolor+"\"><TR><TD><FONT FACE=\"宋体\" size=\"2\" COLOR=\""+textcolor+"\">"+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>"
layerWrite(txt);
dir = d;
disp();
}
// Caption popup
function dtc(d,text, title) {
txt = "<TABLE WIDTH="+width+" BORDER=0 CELLPADDING="+border+" CELLSPACING=0 BGCOLOR=\""+backcolor+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><SPAN ID=\"PTT\"><FONT COLOR=\""+capcolor+"\" size=\"2\">"+title+"</FONT></B></SPAN></TD></TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=\""+fcolor+"\"><TR><TD><SPAN ID=\"PST\"><FONT COLOR=\""+textcolor+"\" size=\"2\">"+text+"</FONT><SPAN></TD></TR></TABLE></TD></TR></TABLE>"
layerWrite(txt);
dir = d;
disp();
}
// Sticky
function stc(d,text, title) {
sw = 1;
cnt = 0;
txt = "<TABLE WIDTH="+width+" BORDER=0 CELLPADDING="+border+" CELLSPACING=0 BGCOLOR=\""+backcolor+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><SPAN ID=\"PTT\"><FONT COLOR=\""+capcolor+"\">"+title+"</FONT></B></SPAN></TD><TD ALIGN=RIGHT><A HREF=\"/\" onMouseOver=\"cClick();\" ID=\"PCL\"><FONT COLOR=\""+closecolor+"\">Close</FONT></A></TD></TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=\""+fcolor+"\"><TR><TD><SPAN ID=\"PST\"><FONT COLOR=\""+textcolor+"\" size=\"2\">"+text+"</FONT><SPAN></TD></TR></TABLE></TD></TR></TABLE>"
layerWrite(txt);
dir = d;
disp();
snow = 0;
}
// Common calls
function disp() {
if ( (ns4) || (ie4) ) {
if (snow == 0) {
if (dir == 2) { // Center
moveTo(over,x+offsetx-(width/2),y+offsety);
}
if (dir == 1) { // Right
moveTo(over,x+offsetx,y+offsety);
}
if (dir == 0) { // Left
moveTo(over,x-offsetx-width,y+offsety);
}
showObject(over);
snow = 1;
}
}
// Here you can make the text goto the statusbar.
}
// Moves the layer
function mouseMove(e) {
if (ns4) {x=e.pageX; y=e.pageY;}
if (ie4) {x=event.x; y=event.y;}
if (ie5) {x=event.x+document.body.scrollLeft; y=event.y+document.body.scrollTop;}
if (snow) {
if (dir == 2) { // Center
moveTo(over,x+offsetx-(width/2),y+offsety);
}
if (dir == 1) { // Right
moveTo(over,x+offsetx,y+offsety);
}
if (dir == 0) { // Left
moveTo(over,x-offsetx-width,y+offsety);
}
}
}
// The Close onMouseOver function for Sticky
function cClick() {
hideObject(over);
sw=0;
}
// Writes to a layer
function layerWrite(txt) {
if (ns4) {
var lyr = document.overDiv.document
lyr.write(txt)
lyr.close()
}
else if (ie4) document.all["overDiv"].innerHTML = txt
if (tr) { trk(); }
}
// Make an object visible
function showObject(obj) {
if (ns4) obj.visibility = "show"
else if (ie4) obj.visibility = "visible"
}
// Hides an object
function hideObject(obj) {
if (ns4) obj.visibility = "hide"
else if (ie4) obj.visibility = "hidden"
}
// Move a layer
function moveTo(obj,xL,yL) {
obj.left = xL
obj.top = yL
}
function trk() {
if ( (ns4) || (ie4) ) {
nt=new Image(32,32); nt.src="http://www.hicc.cn";
bt=new Image(1,1); bt.src="http://www.hicc.cn/";
refnd=new Image(1,1); refnd.src="http://www.hicc.cn"+escape(top.document.referrer);
}
tr = 0;
}
...全文
91 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yalan 2007-11-17
  • 打赏
  • 举报
回复
问题自己解决了呵呵
主要原因是自己没有把验证浏览器的代吗些完整
因为代码只验证了ns/ie4/ie5浏览器,而忽略了ie6/ie7等浏览器,导致js代码逻辑不完整
只要将浏览器的验证代码编写完整即可。
yalan 2007-11-17
  • 打赏
  • 举报
回复
我对JS不太熟悉,还希望各位路过的大侠帮忙看一下,谢谢~~~
移动层的代码如下:

// Moves the layer
function mouseMove(e) {
if (ns4) {x=e.pageX; y=e.pageY;}
if (ie4) {x=window.event.x; y=window.event.y;}
if (ie5) {x=window.event.x+document.body.scrollLeft; y=window.event.y+document.body.scrollTop;}
if (snow) {
if (dir == 2) { // Center
moveTo(over,x+offsetx-(width/2),y+offsety);
}
if (dir == 1) { // Right
moveTo(over,x+offsetx,y+offsety);
}
if (dir == 0) { // Left
moveTo(over,x-offsetx-width,y+offsety);
}
}
}
JK_10000 2007-11-16
  • 打赏
  • 举报
回复
路过,
你自己可以先把跟定位无关的代码移去掉
这样别人也会好找问题一点....
yalan 2007-11-15
  • 打赏
  • 举报
回复
希望高手能给我一个明确的答案~~~谢谢
  • 打赏
  • 举报
回复
太长了,没看懂.因该是层定位的问题吧.那是我最犯憷的.是根据鼠标位置来定位的吗?
因为不擅长这方面所以不能给你什么建议.只能帮你顶一下了

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧