国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

拖動層效果,兼容IE和FF!第1/2頁

2019-11-21 02:26:43
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

<!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 ChatHidden()
    {
        document.getElementById("ChatBody").style.display = "none";
    }
    function ChatShow()
    {
        document.getElementById("ChatBody").style.display = "";
    }
    function ChatClose()
    {
        document.getElementById("main").style.display = "none";
    }
    function ChatSend(obj)
    {
        var o = obj.ChatValue;
        if (o.value.length>0){
            document.getElementById("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(temp.style.left+0);
                        dy = parseInt(temp.style.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">
    <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>

一個拖動效果,根據論壇的一些帖子改的,但還有一些BUG一直沒法解決,誰能幫我改改?
當第一次拖動層時,層的位置會偏離很遠。
呃。。。這涉及到一個style的問題。。。
在ie和firefox中,obj.style這個東西實際上只是取得元素中屬性style中的值!
如下例,你會發現style塊中的屬性一個都取不到!
復制代碼 代碼如下:

<style>
#test{width:100px;background-color:red;}
</style>
<script>
window.onload=function(){
var t=document.getElementById('test')
var ts=t.style;
t.innerHTML=
"t.style.width:"+ts.width+"<br />"+
"t.style.backgroundColor:"+ts.backgroundColor+"<br />"+
"t.style.color:"+ts.color+"<br />"+
"t.style.paddingLeft:"+ts.paddingLeft
}
</script>
<body>
<div id="test" style="color:yellow;padding-left:100px;">
</div>
</body>

看到了沒?前兩個style 為空,后兩個才有值。
如果是ie,問題很好解決,只要把style改成currentStyle即可。
IE Only
復制代碼 代碼如下:

<style>
#test{width:100px;background-color:red;}
</style>
<script>
window.onload=function(){
var t=document.getElementById('test')
var ts=t.currentStyle;
t.innerHTML=
"t.style.width:"+ts.width+"<br />"+
"t.style.backgroundColor:"+ts.backgroundColor+"<br />"+
"t.style.color:"+ts.color+"<br />"+
"t.style.paddingLeft:"+ts.paddingLeft
}
</script>
<body>
<div id="test" style="color:yellow;padding-left:100px;">
</div>
</body>

FF only
復制代碼 代碼如下:

<style>
#test{width:100px;background-color:red;}
</style>
<script>
window.onload=function(){
var t=document.getElementById('test')
var ts=document.defaultView.getComputedStyle(t, null);
t.innerHTML=
"t.style.width:"+ts.width+"<br />"+
"t.style.backgroundColor:"+ts.backgroundColor+"<br />"+
"t.style.color:"+ts.color+"<br />"+
"t.style.paddingLeft:"+ts.paddingLeft
}
</script>
<body>
<div id="test" style="color:yellow;padding-left:100px;">
</div>
</body>

我繞了半天,你明白你的錯誤原因了嗎?你的style全都是文檔級style,而你試圖獲取left的時候,第一次獲得的只是0,自然會把你的框給挪到邊上去了。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大安市| 鹿泉市| 惠来县| 岑巩县| 天峨县| 台北市| 偃师市| 乌鲁木齐县| 贡山| 秦皇岛市| 贵定县| 海盐县| 沧州市| 屯昌县| 新沂市| 民丰县| 建宁县| 霞浦县| 临桂县| 聂荣县| 景宁| 沽源县| 丰县| 新竹县| 冕宁县| 禹州市| 托里县| 德庆县| 滨州市| 泗阳县| 通河县| 平定县| 固原市| 余干县| 晋州市| 襄汾县| 手机| 当阳市| 翁牛特旗| 綦江县| 长兴县|