가운데 표는 검색 양식을 나타냅니다. 제품 카테고리를 클릭하면 상자가 검색창을 가리키며 사용자에게 제품 카테고리를 클릭한 후 변경된 사항을 명확하게 알려줍니다.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>方框移动</TITLE> <style language="javascript"> <!-- body, td{ font-size: 9pt; } --> </style> </HEAD> <BODY> <SCRIPT LANGUAGE="JavaScript"> <!-- var speed=10;//速度 var ci = 10;//运动次数 var left=0;//方框左位置 var top=0;//方框上位置 var width=0;//方框宽 var height=0;//方框高 var aimleft=0;//目标左位置 var aimtop=0;//目标上位置 var aimwidth=0;//目标宽 var aimheight=0;//目标高 var lb=0;//左步长 var tb=0;//上步长 var wb=0;//宽步长 var hb=0;//高步长 /* * 取得对象位置、大小 * 取得目标对象位置、大小 */ function setSource(obj){ left = getOffset(obj).Left; top = getOffset(obj).Top; width = obj.offsetWidth; height = obj.offsetHeight; aimleft = getOffset(aim).Left; aimtop = getOffset(aim).Top; aimwidth = aim.offsetWidth; aimheight = aim.offsetHeight; fk.style.display=''; } /** * 设置方向步长、宽高步长 */ function setStep(){ lb = (aimleft-left)/ci; tb = (aimtop-top)/ci; wb = (aimwidth-width)/ci; hb = (aimheight-height)/ci; } /** * 移动 */ function move(){ setStep(); left+=lb; top+=tb; width+=wb; height+=hb; if(left<aimleft-2 || top<aimtop-2 || width<aimwidth-2 || height<aimheight-2){ fk.style.posLeft = left; fk.style.posTop = top; fk.style.posWidth = width; fk.style.posHeight = height; }else{ hiddenFK(); function() {clearInterval(MyMar)} } } function hiddenFK(){ fk.style.display='none'; } /** * 取得某元素在页面中相对页面左上顶点的位置 */ function getOffset(obj){ var offsetleft = obj.offsetLeft; var offsettop = obj.offsetTop; while (obj.offsetParent != document.body) { obj = obj.offsetParent; offsetleft += obj.offsetLeft; offsettop += obj.offsetTop; } return {Left : offsetleft, Top : offsettop}; } var MyMar=setInterval(move,speed); //--> </SCRIPT> <div id="fk" style="position: absolute; width: 46px; height: 20px; border: 1px solid #000000 ; display: none"></div> <TABLE style="border: 1px solid #666666" cellspacing=1 bgcolor=#ff1111 cellpadding=4 border=0> <TR bgcolor=#ffffff> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">笔记本</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">小家电</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">电冰箱</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">波比娃娃</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">小家电</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">小家电</TD> </TR> </TABLE> <TABLE id="aim" style="border: 1px solid #666666 ; width: 227px; height: 300px;"> <TR> <TD></TD> </TR> </TABLE> <TABLE style="border: 1px solid #666666" cellspacing=1 bgcolor=#ff1111 cellpadding=4 border=0> <TR bgcolor=#ffffff> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">笔记本</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">小家电</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">电冰箱</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">波比娃娃</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">小家电</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">小家电</TD> </TR> </TABLE> </BODY> </HTML>
ㅎㅎ 효과는 좋은데 ff 밑에 자잘한 문제가 있어서 수정했습니다. 세분화 추가
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>方框移动</TITLE> <meta http-equiv="Content-Type" content="text/html; charset=GBK"> <style language="javascript"> <!-- body, td{ font-size: 9pt; } --> </style> </HEAD> <BODY> <SCRIPT LANGUAGE="JavaScript"> <!-- var speed=10;//速度 var ci = 10;//运动次数 var left=0;//方框左位置 var top=0;//方框上位置 var width=0;//方框宽 var height=0;//方框高 var aimleft=0;//目标左位置 var aimtop=0;//目标上位置 var aimwidth=0;//目标宽 var aimheight=0;//目标高 var lb=0;//左步长 var tb=0;//上步长 var wb=0;//宽步长 var hb=0;//高步长 var fk = null; var aim = null; function initObj(){ if (!fk){fk = document.getElementById('fk');} if (!aim){aim = document.getElementById('aim');} } /* * 取得对象位置、大小 * 取得目标对象位置、大小 */ function setSource(obj){ initObj(); left = getOffset(obj).Left; top = getOffset(obj).Top; width = obj.offsetWidth; height = obj.offsetHeight; aimleft = getOffset(aim).Left; aimtop = getOffset(aim).Top; aimwidth = aim.offsetWidth; aimheight = aim.offsetHeight; fk.style.display=''; clearInterval(MyMar); } /** * 设置方向步长、宽高步长 */ function setStep(){ lb = (aimleft-left)/ci; tb = (aimtop-top)/ci; wb = (aimwidth-width)/ci; hb = (aimheight-height)/ci; } /** * 移动 */ function move(){ setStep(); left+=lb; top+=tb; width+=wb; height+=hb; if(left<aimleft-2 || top<aimtop-2 || width<aimwidth-2 || height<aimheight-2){ fk.style.left = left+"px"; fk.style.top = top+"px"; fk.style.width = width+"px"; fk.style.height = height+"px"; }else{ hiddenFK(); clearInterval(MyMar) } } function hiddenFK(){ initObj(); fk.style.display='none'; } /** * 取得某元素在页面中相对页面左上顶点的位置 */ function getOffset(obj){ var offsetleft = obj.offsetLeft; var offsettop = obj.offsetTop; while (obj.offsetParent != document.body) { obj = obj.offsetParent; offsetleft += obj.offsetLeft; offsettop += obj.offsetTop; } return {Left : offsetleft, Top : offsettop}; } var MyMar=setInterval(move,speed); //--> </SCRIPT> <div id="fk" style="position: absolute; width: 46px; height: 20px; border: 1px solid #000000 ; display: none"></div> <TABLE style="border: 1px solid #666666" cellspacing=1 bgcolor=#ff1111 cellpadding=4 border=0> <TR bgcolor=#ffffff> <TD onClick="setSource(this);MyMar=setInterval(move,speed)">笔记本</TD> <TD onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</TD> <TD onClick="setSource(this);{MyMar=setInterval(move,speed)}">电冰箱</TD> <TD onClick="setSource(this);{MyMar=setInterval(move,speed)}">波比娃娃</TD> <TD onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</TD> <TD onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</TD> </TR> </TABLE> <TABLE id="aim" style="border: 1px solid #666666 ; width: 227px; height: 300px;"> <TR> <TD></TD> </TR> </TABLE> <TABLE style="border: 1px solid #666666" cellspacing=1 bgcolor=#ff1111 cellpadding=4 border=0> <TR bgcolor=#ffffff> <TD onClick="setSource(this);{MyMar=setInterval(move,speed)}">笔记本</TD> <TD onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</TD> <TD onClick="setSource(this);{MyMar=setInterval(move,speed)}">电冰箱</TD> <TD onClick="setSource(this);{MyMar=setInterval(move,speed)}">波比娃娃</TD> <TD onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</TD> <TD onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</TD> </TR> </TABLE> </BODY> </HTML>
마우스 프롬프트 추가
div로 변경 후
<html> <HEAD> <TITLE>方框移动</TITLE> <meta http-equiv="Content-Type" content="text/html; charset=GBK"> <style language="javascript"> <!-- body, div{ font-size: 9pt; } ul { margin:0; padding:0} li { width:50px; background:#fff; float:left; cursor:pointer; border:1px solid #f11; text-align:center ; margin:3px; display:block} --> </style> </HEAD> <BODY> <SCRIPT LANGUAGE="JavaScript"> <!-- var speed=10;//速度 var ci = 10;//运动次数 var left=10;//方框左位置 var top=20;//方框上位置 var width=0;//方框宽 var height=0;//方框高 var aimleft=0;//目标左位置 var aimtop=0;//目标上位置 var aimwidth=0;//目标宽 var aimheight=0;//目标高 var lb=0;//左步长 var tb=0;//上步长 var wb=0;//宽步长 var hb=0;//高步长 var fk = null; var aim = null; function initObj(){ if (!fk){fk = document.getElementById('fk');} if (!aim){aim = document.getElementById('aim');} } /* * 取得对象位置、大小 * 取得目标对象位置、大小 */ function setSource(obj){ initObj(); left = getOffset(obj).Left; top = getOffset(obj).Top; width = obj.offsetWidth; height = obj.offsetHeight; aimleft = getOffset(aim).Left; aimtop = getOffset(aim).Top; aimwidth = aim.offsetWidth; aimheight = aim.offsetHeight; fk.style.display=''; clearInterval(MyMar); } /** * 设置方向步长、宽高步长 */ function setStep(){ lb = (aimleft-left)/ci; tb = (aimtop-top)/ci; wb = (aimwidth-width)/ci; hb = (aimheight-height)/ci; } /** * 移动 */ function move(){ setStep(); left+=lb; top+=tb; width+=wb; height+=hb; if(left<aimleft-2 || top<aimtop-2 || width<aimwidth-2 || height<aimheight-2){ fk.style.left = left+"px"; fk.style.top = top+"px"; fk.style.width = width+"px"; fk.style.height = height+"px"; }else{ hiddenFK(); clearInterval(MyMar) } } function hiddenFK(){ initObj(); fk.style.display='none'; } /** * 取得某元素在页面中相对页面左上顶点的位置 */ function getOffset(obj){ var offsetleft = obj.offsetLeft; var offsettop = obj.offsetTop; while (obj.offsetParent != document.body) { obj = obj.offsetParent; offsetleft += obj.offsetLeft; offsettop += obj.offsetTop; } return {Left : offsetleft, Top : offsettop}; } var MyMar=setInterval(move,speed); //--> </SCRIPT> <div id="fk" style="position: absolute; width: 46px; height: 20px; border: 1px solid #000000 ; display: none"></div> <ul> <li onClick="setSource(this);MyMar=setInterval(move,speed)">笔记本</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">电冰箱</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">波比娃娃</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</li> </ul> <div id="aim" style=" clear:left;border: 1px solid #666666 ; width: 227px; height: 300px; margin:20px 10px"> </div> <ul> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">笔记本</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">电冰箱</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">波比娃娃</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</li> </ul> </BODY> </HTML>
var left=10;//상자 왼쪽 위치
var top = 20;//상자에 위치
이 두 정의의 구체적인 용도가 무엇인지 모르겠습니다.
엄격한 인증 하에서는 어떻게 조정해도 10PX 정도의 차이가 나는데 왜 그럴까요?
크기를 변경해도 효과에는 영향이 없는 것 같습니다.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <HEAD> <TITLE>方框移动</TITLE> <meta http-equiv="Content-Type" content="text/html; charset=GBK"> <style language="javascript"> <!-- body, div{ font-size: 9pt; } ul { margin:0; padding:0} li { width:50px; background:#fff; float:left; cursor:pointer; border:1px solid #f11; text-align:center ; margin:3px; display:block} --> </style> </HEAD> <BODY> <SCRIPT LANGUAGE="JavaScript"> <!-- var speed=10;//速度 var ci = 10;//运动次数 var left=0;//方框左位置 var top=0;//方框上位置 var width=0;//方框宽 var height=0;//方框高 var aimleft=0;//目标左位置 var aimtop=0;//目标上位置 var aimwidth=0;//目标宽 var aimheight=0;//目标高 var lb=0;//左步长 var tb=0;//上步长 var wb=0;//宽步长 var hb=0;//高步长 var fk = null; var aim = null; function initObj(){ if (!fk){fk = document.getElementById('fk');} if (!aim){aim = document.getElementById('aim');} } /* * 取得对象位置、大小 * 取得目标对象位置、大小 */ function setSource(obj){ initObj(); left = getOffset(obj).Left; top = getOffset(obj).Top; width = obj.offsetWidth; height = obj.offsetHeight; aimleft = getOffset(aim).Left; aimtop = getOffset(aim).Top; aimwidth = aim.offsetWidth; aimheight = aim.offsetHeight; fk.style.display=''; clearInterval(MyMar); } /** * 设置方向步长、宽高步长 */ function setStep(){ lb = (aimleft-left)/ci; tb = (aimtop-top)/ci; wb = (aimwidth-width)/ci; hb = (aimheight-height)/ci; } /** * 移动 */ function move(){ setStep(); left+=lb; top+=tb; width+=wb; height+=hb; if(left<aimleft-2 || top<aimtop-2 || width<aimwidth-2 || height<aimheight-2){ fk.style.left = left+"px"; fk.style.top = top+"px"; fk.style.width = width+"px"; fk.style.height = height+"px"; }else{ hiddenFK(); clearInterval(MyMar) } } function hiddenFK(){ initObj(); fk.style.display='none'; } /** * 取得某元素在页面中相对页面左上顶点的位置 */ function getOffset(obj){ var offsetleft = obj.offsetLeft; var offsettop = obj.offsetTop; while (obj.offsetParent != document.body) { obj = obj.offsetParent; offsetleft += obj.offsetLeft; offsettop += obj.offsetTop; } return {Left : offsetleft, Top : offsettop}; } var MyMar=setInterval(move,speed); //--> </SCRIPT> <div id="fk" style="position: absolute; width: 46px; height: 20px; border: 1px solid #000000 ; display: none"></div> <ul> <li onClick="setSource(this);MyMar=setInterval(move,speed)">笔记本</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">电冰箱</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">波比娃娃</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</li> </ul> <div id="aim" style=" clear:left;border: 1px solid #666666 ; width: 227px; height: 300px; margin:20px 10px"> </div> <ul> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">笔记本</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">电冰箱</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">波比娃娃</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</li> <li onClick="setSource(this);{MyMar=setInterval(move,speed)}">小家电</li> </ul> </BODY> </HTML>
그라데이션 배경색을 추가한 후 속도가 느려집니다.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>方框移动</TITLE> <style language="javascript"> <!-- body, td{ font-size: 9pt;FILTER: progid:DXImageTransform.Microsoft.Gradient(gradientType=1,startColorStr=#ffffff,endColorStr=#999999); } --> </style> </HEAD> <BODY> <SCRIPT LANGUAGE="JavaScript"> <!-- var speed=10;//速度 var ci = 10;//运动次数 var left=0;//方框左位置 var top=0;//方框上位置 var width=0;//方框宽 var height=0;//方框高 var aimleft=0;//目标左位置 var aimtop=0;//目标上位置 var aimwidth=0;//目标宽 var aimheight=0;//目标高 var lb=0;//左步长 var tb=0;//上步长 var wb=0;//宽步长 var hb=0;//高步长 /* * 取得对象位置、大小 * 取得目标对象位置、大小 */ function setSource(obj){ left = getOffset(obj).Left; top = getOffset(obj).Top; width = obj.offsetWidth; height = obj.offsetHeight; aimleft = getOffset(aim).Left; aimtop = getOffset(aim).Top; aimwidth = aim.offsetWidth; aimheight = aim.offsetHeight; fk.style.display=''; } /** * 设置方向步长、宽高步长 */ function setStep(){ lb = (aimleft-left)/ci; tb = (aimtop-top)/ci; wb = (aimwidth-width)/ci; hb = (aimheight-height)/ci; } /** * 移动 */ function move(){ setStep(); left+=lb; top+=tb; width+=wb; height+=hb; if(left<aimleft-2 || top<aimtop-2 || width<aimwidth-2 || height<aimheight-2){ fk.style.posLeft = left; fk.style.posTop = top; fk.style.posWidth = width; fk.style.posHeight = height; }else{ hiddenFK(); function() {clearInterval(MyMar)} } } function hiddenFK(){ fk.style.display='none'; } /** * 取得某元素在页面中相对页面左上顶点的位置 */ function getOffset(obj){ var offsetleft = obj.offsetLeft; var offsettop = obj.offsetTop; while (obj.offsetParent != document.body) { obj = obj.offsetParent; offsetleft += obj.offsetLeft; offsettop += obj.offsetTop; } return {Left : offsetleft, Top : offsettop}; } var MyMar=setInterval(move,speed); //--> </SCRIPT> <center> <div id="fk" style="position: absolute; width: 46px; height: 20px; border: 1px solid #000000 ; display: none">rerererer</div> <TABLE style="border: 1px solid #666666" cellspacing=1 bgcolor=#ff1111 cellpadding=4 border=0> <TR bgcolor=#ffffff> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">爱老虎油</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">野火寒烟 </TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">剑气凌人</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">火焰楼兰</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">萧萧小雨</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">筷子一根</TD> </TR> </TABLE> <TABLE id="aim" style="border: 1px solid #666666 ; width: 227px; height: 300px;"> <TR> <TD></TD> </TR> </TABLE> <TABLE style="border: 1px solid #666666" cellspacing=1 bgcolor=#ff1111 cellpadding=4 border=0> <TR bgcolor=#ffffff> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">心灵鼓手</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">心开风神 </TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">中国丫头 </TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">波比娃娃</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">乱世狂闪</TD> <TD onClick="setSource(this);function(){MyMar=setInterval(move,speed)}">红心男孩</TD> </TR> </TABLE> </BODY> </HTML>
원리:
pixelTop과 offsetTop은 다르며, pixelTop은 실제로 숫자입니다. 상의 형태. 그리고 offsetTop은 객체의 실제 오프셋입니다.
처음에는 이 fk 객체의 상단이 정의되지 않아 pixelTop이 0이고, 실제 margin 값인 body의 margin이 존재하기 때문에 offsetTop은 0이 아닙니다.