拖動(dòng)層效果,兼容IE和FF!
更新時(shí)間:2006年11月30日 00:00:00 作者:
最終效果
復(fù)制代碼 代碼如下:
<!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=gb2312">
<meta http-equiv="content-script-type" content="text/javascript">
<meta http-equiv="content-style-type" content="text/css">
<title>DoDi Chat v1.0 Beta</title>
<style rel="stylesheet" type="text/css" media="all" />
<!--
body {
text-align:left;
margin:0;
font:normal 12px Verdana, Arial;
background:#FFEEFF
}
form {
margin:0;
font:normal 12px Verdana, Arial;
}
table,input {
font:normal 12px Verdana, Arial;
}
a:link,a:visited{
text-decoration:none;
color:#333333;
}
a:hover{
text-decoration:none;
color:#FF6600
}
#main {
width:400px;
position:absolute;
left:600px;
top:100px;
background:#EFEFFF;
text-align:left;
filter:Alpha(opacity=90)
}
#ChatHead {
text-align:right;
padding:3px;
border:1px solid #003399;
background:#DCDCFF;
font-size:11px;
color:#3366FF;
cursor:move;
}
#ChatHead a:link,#ChatHead a:visited, {
font-size:14px;
font-weight:bold;
padding:0 3px
}
#ChatBody {
border:1px solid #003399;
border-top:none;
padding:2px;
}
#ChatContent {
height:200px;
padding:6px;
overflow-y:scroll;
word-break: break-all
}
#ChatBtn {
border-top:1px solid #003399;
padding:2px
}
-->
</style>
<script language="javascript" type="text/javascript">
<!--
function $(d){return document.getElementById(d);}
function gs(d){var t=$(d);if (t){return t.style;}else{return null;}}
function gs2(d,a){
if (d.currentStyle){
var curVal=d.currentStyle[a]
}else{
var curVal=document.defaultView.getComputedStyle(d, null)[a]
}
return curVal;
}
function ChatHidden(){gs("ChatBody").display = "none";}
function ChatShow(){gs("ChatBody").display = "";}
function ChatClose(){gs("main").display = "none";}
function ChatSend(obj){
var o = obj.ChatValue;
if (o.value.length>0){
$("ChatContent").innerHTML += "<strong>Akon說:</strong>"+o.value+"<br/>";
o.value='';
}
}
if (document.getElementById){
(
function(){
if (window.opera){ document.write("<input type='hidden' id='Q' value=' '>"); }
var n = 500;
var dragok = false;
var y,x,d,dy,dx;
function move(e)
{
if (!e) e = window.event;
if (dragok){
d.style.left = dx + e.clientX - x + "px";
d.style.top = dy + e.clientY - y + "px";
return false;
}
}
function down(e){
if (!e) e = window.event;
var temp = (typeof e.target != "undefined")?e.target:e.srcElement;
if (temp.tagName != "HTML"|"BODY" && temp.className != "dragclass"){
temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
}
if('TR'==temp.tagName){
temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
}
if (temp.className == "dragclass"){
if (window.opera){ document.getElementById("Q").focus(); }
dragok = true;
temp.style.zIndex = n++;
d = temp;
dx = parseInt(gs2(temp,"left"))|0;
dy = parseInt(gs2(temp,"top"))|0;
x = e.clientX;
y = e.clientY;
document.onmousemove = move;
return false;
}
}
function up(){
dragok = false;
document.onmousemove = null;
}
document.onmousedown = down;
document.onmouseup = up;
}
)();
}
-->
</script>
</head>
<body>
<div id="main" class="dragclass" style="left:600px;top:300px;">
<div id="ChatHead">
<a href="#" onclick="ChatHidden();">-</a>
<a href="#" onclick="ChatShow();">+</a>
<a href="#" onclick="ChatClose();">x</a>
</div>
<div id="ChatBody">
<div id="ChatContent"></div>
<div id="ChatBtn">
<form action="" name="chat" method="post">
<textarea name="ChatValue" rows="3" style="width:350px"></textarea>
<input name="Submit" type="button" value="Chat" onclick="ChatSend(this.form);" />
</form>
</div>
</div>
</div>
</body>
</html>
附解決問題的過程:
1、首先debug,看表現(xiàn),就知道是在第一次點(diǎn)擊的時(shí)候,對(duì)象的左右邊距出錯(cuò),變成0
2、找到代碼中對(duì)應(yīng)位置,輸出left和top
3、知道原因,我之前已經(jīng)知道currentStyle的效果,所以我不需要去網(wǎng)絡(luò)上搜索相關(guān)資料
4、但是我不知道在firefox下如何處理
5、我在google里直接搜索“currentStyle firefox”,很快就找到符合我目的的信息
6、測(cè)試通過,發(fā)帖子。
相關(guān)文章
深入理解JavaScript是如何實(shí)現(xiàn)繼承的
這篇文章主要介紹了JavaScript是如何實(shí)現(xiàn)繼承的,有需要的朋友可以參考一下2013-12-12javascript類型系統(tǒng) Window對(duì)象學(xué)習(xí)筆記
這篇文章主要介紹了javascript類型系統(tǒng)之Window對(duì)象,整理關(guān)于Window對(duì)象的學(xué)習(xí)筆記,感興趣的小伙伴們可以參考一下2016-01-01Mozilla 表達(dá)式 __noSuchMethod__
這是一個(gè)很特殊的方法,但是其存在的意義很大。不過很可惜只有firefox支持了。一個(gè)簡(jiǎn)單的例子解釋一下它的用處2009-04-04js實(shí)現(xiàn)頁(yè)面a向頁(yè)面b傳參的方法
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)頁(yè)面a向頁(yè)面b傳參的方法,感興趣的小伙伴們可以參考一下2016-05-05JavaScript中實(shí)現(xiàn)跨標(biāo)簽頁(yè)通信的方法詳解
跨標(biāo)簽頁(yè)通信是指在瀏覽器中的不同標(biāo)簽頁(yè)之間進(jìn)行數(shù)據(jù)傳遞和通信的過程,這篇文章為大家介紹了一下常見的跨標(biāo)簽頁(yè)通信方式,感興趣的小伙伴可以了解下2023-11-11javascript用rem來做響應(yīng)式開發(fā)
這篇文章主要介紹了javascript用rem來做響應(yīng)式開發(fā),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-01-01Bootstrap3 datetimepicker控件使用實(shí)例
這篇文章主要為大家詳細(xì)介紹了Bootstrap3 datetimepicker控件使用實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12JavaScript數(shù)組方法-系統(tǒng)性總結(jié)詳解
本文是小編給大家特意整理的關(guān)于js數(shù)組方法的知識(shí),非常實(shí)用,在面試筆試題中經(jīng)常用得到,有需要的朋友可以參考下2021-09-09