Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
648f0833
Commit
648f0833
authored
Mar 27, 2006
by
John Resig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Ian Eure's (atomized.org) Drag and Drop code to the repository, for further testing.
parent
a027d25f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
drag.js
drag/drag.js
+71
-0
No files found.
drag/drag.js
0 → 100644
View file @
648f0833
$
.
drug
=
null
;
$
.
dragstart
=
function
(
e
)
{
this
.
dragElement
.
deltaX
=
e
.
clientX
-
this
.
dragElement
.
offsetLeft
;
this
.
dragElement
.
deltaY
=
e
.
clientY
-
this
.
dragElement
.
offsetTop
;
// Save CSS
this
.
dragElement
.
oldPos
=
$
.
css
(
this
.
dragElement
,
'position'
);
this
.
dragElement
.
oldCursor
=
$
.
css
(
this
.
dragElement
,
'cursor'
);
this
.
dragElement
.
oldUserSelect
=
$
.
css
(
this
.
dragElement
,
'user-select'
);
$
(
this
.
dragElement
).
css
(
'position'
,
'absolute'
)
.
css
(
'cursor'
,
'move'
)
.
css
(
'user-select'
,
'none'
);
$
.
drug
=
this
.
dragElement
;
};
$
.
dragstop
=
function
(
e
)
{
$
.
drug
=
null
;
// Restore CSS
$
(
this
).
css
(
'cursor'
,
this
.
oldCursor
)
.
css
(
'user-select'
,
this
.
oldUserSelect
);
}
$
.
drag
=
function
(
e
)
{
if
(
$
.
drug
==
null
)
{
return
;
}
// Update position
var
nx
=
(
e
.
clientX
-
$
.
drug
.
deltaX
);
var
ny
=
(
e
.
clientY
-
$
.
drug
.
deltaY
);
// Bounds check
// Left edge
nx
=
(
nx
<
0
)
?
0
:
nx
;
// right edge
nx
=
(
nx
+
$
.
drug
.
offsetWidth
)
>
document
.
width
?
document
.
width
-
$
.
drug
.
offsetWidth
:
nx
;
// Top
ny
=
(
ny
<
window
.
scrollY
)
?
window
.
scrollY
:
ny
;
// Bottom
ny
=
(
ny
+
$
.
drug
.
offsetHeight
)
>
window
.
innerHeight
+
window
.
scrollY
?
window
.
innerHeight
+
window
.
scrollY
-
$
.
drug
.
offsetHeight
:
ny
;
$
(
$
.
drug
).
css
(
'left'
,
nx
+
'px'
)
.
css
(
'top'
,
ny
+
'px'
);
};
$
.
draginit
=
false
;
$
.
fn
.
Draggable
=
function
(
handle
)
{
// Don't add > 1 of these handlers
if
(
!
$
.
draginit
)
{
$
(
document
).
bind
(
'mousemove'
,
$
.
drag
);
}
return
this
.
each
(
function
()
{
var
dhe
=
handle
?
$
(
this
).
find
(
handle
)
:
$
(
this
);
dhe
.
get
(
0
).
dragElement
=
this
;
dhe
.
bind
(
'mousedown'
,
$
.
dragstart
)
.
bind
(
'mouseup'
,
$
.
dragstop
);
});
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment