MozTW 討論區

各項 Mozilla 相關軟體與技術討論
現在的時間是 2025-08-23, 00:19

所有顯示的時間為 UTC + 8 小時





發表新文章 這個主題已被鎖定,您不能編輯或回覆這個主題。  [ 4 篇文章 ] 
發表人 內容
文章發表於 : 2007-03-15, 01:08 
我寫了一段code想讓鼠標移到某些字時讓div tag出現在該字的下方
在IE裡可以跑了,不過FF不行,不知道是不是event.clientx的問題?有人遇過這種問題嗎,謝謝大家
範例:http://joehwang.myweb.hinet.net/1.htm
代碼:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
<title>test</title>

<style type="text/css">
<!--
.popwin {
   font-family: Arial, Helvetica, sans-serif;
   
   position: absolute;
   top: 0px;
   right: 0px;
   border: 2pt solid #FFFFFF;
   background-color: #FFFBF0;
   font-size: 10pt;
   height: 100px;
   width: 100px;
}
-->
</style>
</head>


<script>
//單字pop程式
function popword(e){//設定出現的位置
//document.getElementById("popwin").style.left=(window.event.offsetX)+150;
//document.getElementById("popwin").style.top=(window.event.offsetY)+40;

document.getElementById("popwin").style.left=event.clientX+document.body.scrollLeft+10;
document.getElementById("popwin").style.top=event.clientY+document.body.scrollTop+10;
}
function popstart(a,b,c){//帶入中文、詞性、單字,啟動單字pop
document.getElementById("popwin").style.display="block";
document.getElementById("popwin").innerHTML="<div class=poptop>"+c+"</div><div class=popdown>"+a+b+"</div>";
document.onmousemove=popword;
}
function popclose(){//關掉單字pop
document.getElementById("popwin").style.display="None"

}
//單字pop結束
</script>

<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="center"><a onMouseOver="popstart('test','test','test')" onmouseout="popclose()">點我</a></p>
<span id="popwin" class="popwin"></span>
</body>
</html>


回頂端
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)
  
 
 文章主題 :
文章發表於 : 2007-03-15, 01:11 
離線
頭像

註冊時間: 2006-10-27, 07:29
文章: 1068
我記得IE的DOM樹和其他有點不太一樣
你試試把event當成引數傳進函式裡看看


回頂端
Mozilla/5.0 (X11; U; Linux i686; zh-TW; rv:1.8.1.2) Gecko/20060601 Firefox/2.0.0.2 (Ubuntu-edgy)
 個人資料  
 
 文章主題 :
文章發表於 : 2007-03-16, 00:26 
哈,改好了,原來是要加"px",且popword()這function在FF中需要帶引數(mouse事件),而ie不能帶引數,把改好的code分享的大家。
代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
<title>test</title>

<style type="text/css">
<!--
.popwin {
   font-family: Arial, Helvetica, sans-serif;
   
   position: absolute;
   top: 0px;
   right: 0px;
   border: 2pt solid #FFFFFF;
   background-color: #FFFBF0;
   font-size: 10pt;
   height: 100px;
   width: 100px;
}
-->
</style>
</head>


<script>
//單字pop程式
function popword(e){//設定出現的位置
//document.getElementById("popwin").style.left=(window.event.offsetX)+150;
//document.getElementById("popwin").style.top=(window.event.offsetY)+40;

if(!e) e=window.event;
//firefox要有mouse事件傳進來,而IE傳進來會出錯,在此判斷使兩者相容

document.getElementById("popwin").style.left=e.clientX+10+"px";
document.getElementById("popwin").style.top=e.clientY+10+"px";
}
function popstart(a,b,c,event){//帶入中文、詞性、單字,啟動單字pop
document.getElementById("popwin").style.display="block";
document.getElementById("popwin").innerHTML="<div class=poptop>"+c+"</div><div class=popdown>"+a+b+"</div>";
document.onmousemove=popword;
//在網頁上做move的動作會引發popword的function
}
function popclose(){//關掉單字pop
document.getElementById("popwin").style.display="None"
}
//單字pop結束
</script>

<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="center"><a onMouseOver="popstart('test','test','test',event)" onmouseout="popclose()">點我</a></p>

<span id="popwin" class="popwin"></span>
</body>
</html>



回頂端
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)
  
 
 文章主題 :
文章發表於 : 2007-03-16, 13:12 
離線
[網站管理員]
頭像

註冊時間: 2004-09-27, 09:24
文章: 1685
忘記加 px 是我常犯的毛病XD

_________________
korp + korp 中文站(沒精神更新)


回頂端
Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2
 個人資料  
 
顯示文章 :  排序  
發表新文章 這個主題已被鎖定,您不能編輯或回覆這個主題。  [ 4 篇文章 ] 

所有顯示的時間為 UTC + 8 小時


誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 17 位訪客


不能 在這個版面發表主題
不能 在這個版面回覆主題
不能 在這個版面編輯您的文章
不能 在這個版面刪除您的文章
不能 在這個版面上傳附加檔案

搜尋:
前往 :  
Powered by phpBB® Forum Software © phpBB Group
正體中文語系由 竹貓星球 維護製作
© moztw.org, Mozilla Foundation
MozTW,Mozilla 台灣社群