mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
19 lines
936 B
HTML
19 lines
936 B
HTML
<div id="area" style="position: relative; width: 400px; height: 300px; border: 1px solid #bbb;">
|
|
<img src="templates/images/white.gif" style="width: 400px; height: 300px;"/>
|
|
<img id="target" src="templates/images/target.jpeg" style="position: absolute; left: 0px; top: 0px;"/>
|
|
</div>
|
|
<script type="text/javascript">
|
|
function moveToHere(event, easing) {
|
|
var area = $("#area");
|
|
var target = $("#target");
|
|
var offset = area.offset();
|
|
var max = [area.width() - target.width(), area.height() - target.height()];
|
|
var scroll = [document.documentElement.scrollLeft || document.body.scrollLeft,
|
|
document.documentElement.scrollTop || document.body.scrollTop];
|
|
target.animate({left: Math.max(0, Math.min((event.clientX + scroll[0]) -
|
|
offset.left - (target.width() / 2), max[0])),
|
|
top: Math.max(0, Math.min((event.clientY + scroll[1]) -
|
|
offset.top - (target.height() / 2), max[1]))},
|
|
2000, easing);
|
|
}
|
|
</script> |