◆◆用JS移动一个点到另一个点发生事件.求解! 本帖最后由 j2u1314 于 2010-04-09 14:09:35 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 写A点的 mouseout热点的 mouseover组合实现你的需求 http://www.w3school.com.cn/tiy/t.asp?f=html_areamap参考这个例子吧 onmouseover移入 和onmouseout移出 <img src="Water lilies.jpg" usemap="#map_sample" border="0" alt="sample"><map name="map_sample"><area shape="circle" coords="156,164,5" href="#" alt="円"><area shape="circle" coords="200,85,5" href="#" alt="円"><area shape="poly" coords="156,109 173,154 211,146 217,120 181,99" href="#" alt="多角形"></map><script>var x1=156,y1=164;//Avar x2=200,y2=85;//Bvar b=[[156,109],[173,154],[211,146],[217,120],[181,99]];var mx=0,my=0;//move point stepfunction move(){ if(x1+mx>x2)clearInterval(timer); mx++;//偏移量x my=(y2-y1)*mx/(x2-x1);//偏移量y // 起点y + 相対偏移量x * 斜率 <=移動点y if(b[1][1] + (mx+x1-b[1][0])*(b[0][1]-b[1][1])/(b[0][0]-b[1][0])<=my+y1){//正負号有問題,自己調試 alert((mx+x1)+":"+(my+y1)); clearInterval(timer); } }var timer=setInterval(move,10);</script> 再試試:<img src="Water lilies.jpg" usemap="#map_sample" border="0" alt="sample"><map name="map_sample"><area shape="circle" coords="156,164,5" href="#" alt="円"><area shape="circle" coords="200,85,5" href="#" alt="円"><area shape="poly" coords="156,109 173,154 211,146 217,120 181,99" href="#" alt="多角形"></map><textarea rows=5 cols=10 id=tt1></textarea><script>var x1=156,y1=164;//Avar x2=200,y2=85;//Bvar b=[[156,109],[173,154],[211,146],[217,120],[181,99]];var mx=0,my=0;//move point stepfunction move(){ if(x1+mx>x2)clearInterval(timer); mx++;//偏移量x my=(y2-y1)*mx/(x2-x1);//偏移量y document.getElementById("tt1").value=my // 起点y + 相対偏移量x * 斜率 <=移動点y if(Math.abs(b[0][1] + (x1+mx-b[0][0])*(b[0][1]-b[1][1])/(b[0][0]-b[1][0]))>=y1+my){ alert((mx+x1)+":"+(my+y1)); clearInterval(timer); } }var timer=setInterval(move,10);</script> 大哥.真神了!!.太崇拜你了!!。真的行。而且很准确。但是反方向就不行了。就是上面的点在左边。下面的点在右边。请原谅我的过份请求。如果能把这个问题解决。就太神奇了。JS没有像FALSH那相的碰撞函数。你在JS里都实现了。缺实让人佩服。!!! 反方向,自己判断正負号// 起点y + 相対偏移量x * 斜率 <=移動点y if(Math.abs(b[0][1] + (x1+mx-b[0][0])*(b[0][1]-b[1][1])/(b[0][0]-b[1][0]))>=y1+my){ 推荐基本javascript的书籍 找不到js文件的问题 有没有flash播放器可以读取本地文件的 怎么实现校内的选择大学控件 假分页checkbox 文本框如何只输入英文字母数字下划线,越简单越好 showModalDialog郁闷问题 怎样用Javascript控制网页input框内的时间日期输入格式中必须含有“年”“月”“日”三个字? 一个表单怎样提交到两个页面? 请大家帮忙,谢谢! 打印框架网页的问题 字符串比较的问题,发挥你们的聪明才智 match()
热点的 mouseover
组合实现你的需求
<map name="map_sample">
<area shape="circle" coords="156,164,5" href="#" alt="円">
<area shape="circle" coords="200,85,5" href="#" alt="円">
<area shape="poly" coords="156,109 173,154 211,146 217,120 181,99" href="#" alt="多角形">
</map>
<script>
var x1=156,y1=164;//A
var x2=200,y2=85;//B
var b=[[156,109],[173,154],[211,146],[217,120],[181,99]];
var mx=0,my=0;//move point step
function move(){
if(x1+mx>x2)clearInterval(timer);
mx++;//偏移量x
my=(y2-y1)*mx/(x2-x1);//偏移量y
// 起点y + 相対偏移量x * 斜率 <=移動点y
if(b[1][1] + (mx+x1-b[1][0])*(b[0][1]-b[1][1])/(b[0][0]-b[1][0])<=my+y1){//正負号有問題,自己調試
alert((mx+x1)+":"+(my+y1));
clearInterval(timer);
}
}
var timer=setInterval(move,10);
</script>
<img src="Water lilies.jpg" usemap="#map_sample" border="0" alt="sample">
<map name="map_sample">
<area shape="circle" coords="156,164,5" href="#" alt="円">
<area shape="circle" coords="200,85,5" href="#" alt="円">
<area shape="poly" coords="156,109 173,154 211,146 217,120 181,99" href="#" alt="多角形">
</map>
<textarea rows=5 cols=10 id=tt1></textarea>
<script>
var x1=156,y1=164;//A
var x2=200,y2=85;//B
var b=[[156,109],[173,154],[211,146],[217,120],[181,99]];
var mx=0,my=0;//move point step
function move(){
if(x1+mx>x2)clearInterval(timer);
mx++;//偏移量x
my=(y2-y1)*mx/(x2-x1);//偏移量y
document.getElementById("tt1").value=my
// 起点y + 相対偏移量x * 斜率 <=移動点y
if(Math.abs(b[0][1] + (x1+mx-b[0][0])*(b[0][1]-b[1][1])/(b[0][0]-b[1][0]))>=y1+my){
alert((mx+x1)+":"+(my+y1));
clearInterval(timer);
}
}
var timer=setInterval(move,10);
</script>
大哥.真神了!!.
太崇拜你了!!。真的行。
而且很准确。但是反方向就不行了。就是上面的点在左边。
下面的点在右边。
请原谅我的过份请求。如果能把这个问题解决。就太神奇了。
JS没有像FALSH那相的碰撞函数。
你在JS里都实现了。
缺实让人佩服。!!!
// 起点y + 相対偏移量x * 斜率 <=移動点y
if(Math.abs(b[0][1] + (x1+mx-b[0][0])*(b[0][1]-b[1][1])/(b[0][0]-b[1][0]))>=y1+my){