惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
量子位
T
Tailwind CSS Blog
Vercel News
Vercel News
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
U
Unit 42
Engineering at Meta
Engineering at Meta
L
LangChain Blog
大猫的无限游戏
大猫的无限游戏
D
Docker
博客园_首页
P
Proofpoint News Feed
月光博客
月光博客
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Martin Fowler
Martin Fowler
腾讯CDC
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - KenBlove

错误代码:0x800706BE 解决方法 泛微OA服务器更改IP地址后EMobile出现“调用远端服务器接口时发生错误(122)”的提示 HTTP 错误 404 - 文件或目录未找到 HTTP 错误 401.2 - 未经授权:访问由于服务器配置被拒绝。 优雅还不够,简洁才高效!——用NValidator一句话搞定客户端检测 MyXls初级教程 一个仿PetShop的通用DBHelper类 纯CSS实现底部固定漂浮导航 Access和SQL server开启表间关系,并实现更新或删除母表数据自动更新或删除子表数据 来自微软关于异常处理的17条军规 SQL Server Profiler过滤本机信息的办法 "The state information is invalid for this page and might be corrupted"错误的一个解决办法 SQL回滚Transaction来调试SQL语句 SQL找出和删除一个表的重复记录 SQL常用判断检测语句 SQL把ID相同的记录合并成同一条记录 从丑陋到优雅,让代码越变越美续集之服务器端数据校验 关于FireFox记住密码后出现的bug 关于Iframe在IE6下不显示的bug 从丑陋到优雅,让代码越变越美(客户端检测方法思考)
一个简单的拖动层(兼容IE,FF)
KenBlove · 2009-06-05 · via 博客园 - KenBlove

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>
    
<title>拖动层</title>
    
<style type="text/css">
    .main
    
{
        position
: absolute; 
        background-color
: #fff;
        top
: 100px; 
        left
: 100px; 
        z-index
: 101; 
        border
: solid 1px #ccc;
    
}
    .titlebar
    
{
        background-color
: #ccc; 
        cursor
: move; 
        height
: 20px; 
        color
: #fff;
        font-size
: 13px; 
        padding-top
: 5px; 
        padding-left
: 10px;
    
}
    
</style>
</head>
<body>
    
<div id="main" class="main" style="width: 500px; height: 350px;">
        
<div id="titlebar" class="titlebar">
            拖动层
        
</div>
        
<div id="Div1" class="main" style="width: 200px; height: 50px;">
            
<div id="Div2" class="titlebar">
                拖动层2
            
</div>
        
</div>
    
</div><script type="text/javascript">
        
new drag("main""titlebar");
        
new drag("Div1""Div2");function drag(main, titlebar) {
            
var obj = document.getElementById(main);
            
var title = document.getElementById(titlebar);
            
if(obj && title)
            {            
                
var posX;
                
var posY;
                
var offset = 10;
                
var mousemove = function(evt) {
                    
if (evt == null) evt = window.event;
                    
var left = evt.clientX - posX;
                    
var top = evt.clientY - posY;
                    
var limitLeft = 0;
                    
var limitTop = 0;
                    
if(obj.parentNode.nodeName != "BODY")
                    {
                        limitLeft 
= obj.parentNode.clientWidth - obj.clientWidth - offset;
                        
if(limitLeft < left)
                        {
                            left 
= limitLeft;
                        }
                        limitTop 
= obj.parentNode.clientHeight - obj.clientHeight - offset;
                        
if(limitTop < top)
                        {
                            top 
= limitTop;
                        }
                    }
                    
else
                    {
                        limitLeft 
= window.screen.availWidth - obj.clientWidth - offset;
                        
if(limitLeft < left)
                        {
                            left 
= limitLeft;
                        }
                        limitTop 
= window.screen.availHeight - obj.clientHeight - offset;
                        
if(limitTop < top)
                        {
                            top 
= limitTop;
                        }
                    }
                    
if(left < offset)
                    {
                        left 
= offset;
                    }
                    
if(top < offset)
                    {
                        top 
= offset;
                    }
                    obj.style.left 
= left + "px";
                    obj.style.top 
= top + "px";
                }
                
                title.onmousedown 
= function(evt) {
                    
if (!evt) evt = window.event;
                    posX 
= evt.clientX - obj.offsetLeft;
                    posY 
= evt.clientY - obj.offsetTop;
                    document.onmousemove 
= mousemove;
                }

                document.onmouseup 

= function() {
                    document.onmousemove 
= null;
                }
            }
            
else
            {
                alert(
"参数错误!");
            }
        }
    
</script></body>
</html>