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

推荐订阅源

Know Your Adversary
Know Your Adversary
云风的 BLOG
云风的 BLOG
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
B
Blog
罗磊的独立博客
宝玉的分享
宝玉的分享
Vercel News
Vercel News
Martin Fowler
Martin Fowler
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
T
Threatpost
Security Latest
Security Latest
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Stack Overflow Blog
Stack Overflow Blog
I
Intezer
P
Privacy International News Feed
D
Docker
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
M
MIT News - Artificial intelligence
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
Lohrmann on Cybersecurity
Google DeepMind News
Google DeepMind News
The Last Watchdog
The Last Watchdog
A
Arctic Wolf
IT之家
IT之家
S
SegmentFault 最新的问题
S
Securelist
博客园 - 叶小钗
N
News and Events Feed by Topic
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
Hacker News: Ask HN
Hacker News: Ask HN
博客园 - Franky
GbyAI
GbyAI
AI
AI
Y
Y Combinator Blog
WordPress大学
WordPress大学
Latest news
Latest news
Microsoft Security Blog
Microsoft Security Blog
人人都是产品经理
人人都是产品经理
N
News | PayPal Newsroom
The Cloudflare Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
I
InfoQ

博客园 - 西狐

我眼中的Java架构师 使用命令行写一个 Java Servlet 关于真正的Ajax方式上传文件 用CSS的 filter 来轻松实现图层半透明 用CSS3的 border-radius 来轻松实现图层圆角 用CSS3的 box-shadow 来轻松实现图层阴影效果 VS2010 让你的Javascript代码可以折叠 JSON 转成 C# 动态类 C# 将对象序列化为XML Lamborghini 兰博基尼 Gallardo Lamborghini 兰博基尼 Murcielago Lamborghini 兰博基尼 Reventon Lamborghini 兰博基尼 JavaScript 的 StringBuilder 无法加载"sybdrvado20.dll" 的原因和解决办法 js把 CheckBox 复选框 做成 radio 单选 的效果 搜狗"云"输入法,实现原理. - 西狐 - 博客园 TXT小说下载,交流 贾君鹏你妈妈喊你回家吃饭
用jQuery轻松实现Div拖动
西狐 · 2011-05-20 · via 博客园 - 西狐

用jQuery轻松实现Div拖动,只需只行代码,很简单. 试试效果:

hooyes

代码:

<!DOCTYPE html>
<html>
<head>
<title>hooyes Drag demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"
type
="text/javascript"></script>
<style type="text/css">
.drag
{
position
:absolute;
width
:100px; height:100px;
border
:1px solid #96C2F1; background-color: #EFF7FF;
cursor
:move; line-height:100px; text-align:center;
}
</style>
<script type="text/javascript">
(
function (document) {
//Usage: $("#id").drag()
//Author: hooyes
$.fn.Drag = function () {
var M = false;
var Rx, Ry;
var t = $(this);
t.mousedown(
function (event) {
Rx
= event.pageX - (parseInt(t.css("left")) || 0);
Ry
= event.pageY - (parseInt(t.css("top")) || 0);
t.css(
"position", "absolute").css('cursor', 'move').fadeTo(20, 0.5);
M
= true;
})
.mouseup(
function (event) {
M
= false; t.fadeTo(20, 1);
});
$(document).mousemove(
function (event) {
if (M) {
t.css({ top: event.pageY
- Ry, left: event.pageX - Rx });
}
});
}
})(document);

$(document).ready(

function () {
$(
"#Div1").Drag();
});
</script>
</head>
<body>
<div id="Div1" class="drag">hooyes</div>
</body>
</html>