JavaScript模擬可展開(kāi)、拖動(dòng)與關(guān)閉的聊天窗口實(shí)例
用JavaScript實(shí)現(xiàn)的仿QQ聊天窗口,可以展開(kāi)層、拖動(dòng)層、關(guān)閉層,還可以簡(jiǎn)單發(fā)消息,很不錯(cuò)吧,而且代碼也不多,適合新手研究,也比較實(shí)用,你可以在此基礎(chǔ)上擴(kuò)展很多JS+CSS應(yīng)用。
<!--CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt-->
<html>
<head>
<title>層展開(kāi)、層拖動(dòng)、層關(guān)閉</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css" media="all" rel="stylesheet">
<!--
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說(shuō):</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 class="dragclass" id="main" style="LEFT: 588px; TOP: 298px">
<div id="ChatHead"><a onclick="ChatHidden();" href="#">-</a>
<a onclick="ChatShow();" href="#">+</a>
<a onclick="ChatClose();" href="#">x</a> </div>
<div id="ChatBody">
<div id="ChatContent">HI! Hello ! Welcome to www.dbjr.com.cn</div>
<div id="ChatBtn">
<form action="" method="post" name="chat">
</form>
</div>
</div>
</div>
</body>
</html>
希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。
- js仿百度登錄頁(yè)實(shí)現(xiàn)拖動(dòng)窗口效果
- javascript彈出拖動(dòng)窗口
- JS實(shí)現(xiàn)彈出浮動(dòng)窗口(支持鼠標(biāo)拖動(dòng)和關(guān)閉)實(shí)例詳解
- javascript實(shí)現(xiàn)可拖動(dòng)變色并關(guān)閉層窗口實(shí)例
- javascript實(shí)現(xiàn)漂亮的拖動(dòng)層,窗口拖拽特效
- JS實(shí)現(xiàn)可縮放、拖動(dòng)、關(guān)閉和最小化的浮動(dòng)窗口完整實(shí)例
- javascript div 彈出可拖動(dòng)窗口
- jQuery實(shí)現(xiàn)單擊彈出Div層窗口效果(可關(guān)閉可拖動(dòng))
- Jquery仿IGoogle實(shí)現(xiàn)可拖動(dòng)窗口示例代碼
- 基于JavaScript實(shí)現(xiàn)窗口拖動(dòng)效果
相關(guān)文章
走進(jìn)javascript——不起眼的基礎(chǔ),值和分號(hào)
本文主要介紹了javascript的基礎(chǔ)知識(shí)--值和分號(hào),具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-02-02
JavaScript塊級(jí)作用域綁定的實(shí)現(xiàn)流程
這篇文章主要給大家介紹了關(guān)于JavaScript塊級(jí)作用域綁定的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-12-12
JavaScript設(shè)計(jì)模式之單件模式介紹
這篇文章主要介紹了JavaScript設(shè)計(jì)模式之單件模式介紹,單件模式,就是靜態(tài)化的訪問(wèn)中已經(jīng)實(shí)例化的對(duì)象,這個(gè)對(duì)象只能通過(guò)一個(gè)唯一的入口訪問(wèn),已經(jīng)實(shí)例或待實(shí)例化的對(duì)象,需要的朋友可以參考下2014-12-12
檢測(cè)一個(gè)函數(shù)是否是JavaScript原生函數(shù)的小技巧
這篇文章主要介紹了檢測(cè)一個(gè)函數(shù)是否是JavaScript原生函數(shù)的小技巧,本文給出了兩種檢測(cè)方法,需要的朋友可以參考下2015-03-03

