2012-04-20 15:18:58 +00:00
|
|
|
<!doctype html>
|
2012-04-10 16:11:28 +00:00
|
|
|
<html lang="en">
|
|
|
|
<head>
|
2012-04-20 15:18:58 +00:00
|
|
|
<meta charset="utf-8">
|
2012-05-21 00:34:21 +00:00
|
|
|
<title>Position Visual Test: Feedback</title>
|
2012-04-20 15:18:58 +00:00
|
|
|
<link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css">
|
2012-11-14 20:22:01 +00:00
|
|
|
<script src="../../../jquery-1.8.3.js"></script>
|
2012-04-20 15:18:58 +00:00
|
|
|
<script src="../../../ui/jquery.ui.core.js"></script>
|
|
|
|
<script src="../../../ui/jquery.ui.widget.js"></script>
|
|
|
|
<script src="../../../ui/jquery.ui.position.js"></script>
|
|
|
|
<script src="../../../ui/jquery.ui.menu.js"></script>
|
|
|
|
<script>
|
2012-04-10 16:11:28 +00:00
|
|
|
$(function() {
|
2012-04-11 13:20:30 +00:00
|
|
|
function using( position, feedback ) {
|
2012-04-20 15:18:58 +00:00
|
|
|
$( this )
|
2012-04-20 15:02:50 +00:00
|
|
|
.css( position )
|
2012-04-13 14:05:29 +00:00
|
|
|
.text( feedback.horizontal + " " + feedback.vertical + " " + feedback.important )
|
|
|
|
.removeClass( "left right top bottom center middle vertical horizontal" )
|
|
|
|
.addClass( feedback.horizontal )
|
|
|
|
.addClass( feedback.vertical )
|
|
|
|
.addClass( feedback.important );
|
2012-04-11 13:20:30 +00:00
|
|
|
}
|
2012-04-20 15:18:58 +00:00
|
|
|
|
|
|
|
var element = $( ".element" ),
|
|
|
|
target = $( "#target" ).position({
|
|
|
|
my: "center",
|
|
|
|
at: "center",
|
|
|
|
of: window
|
|
|
|
}),
|
|
|
|
targetOffset = target.offset(),
|
|
|
|
oppositeElement = element.clone().width( 50 ).appendTo( "body" ),
|
|
|
|
leftElement = element.clone().width( 50 ).height( 150 ).appendTo( "body" ),
|
|
|
|
rightElement = element.clone().height( 150 ).width( 150 ).appendTo( "body" );
|
|
|
|
|
2012-04-10 16:11:28 +00:00
|
|
|
$.each([
|
|
|
|
"center top-100",
|
|
|
|
"right+25 top-50",
|
|
|
|
"right+75 top",
|
|
|
|
"right+75 center",
|
|
|
|
"right+75 bottom",
|
|
|
|
"right+25 bottom+50",
|
|
|
|
"center bottom+100",
|
|
|
|
"left-25 bottom+50",
|
|
|
|
"left-75 bottom",
|
|
|
|
"left-75 center",
|
|
|
|
"left-75 top",
|
|
|
|
"left-25 top-50"
|
2012-04-20 15:18:58 +00:00
|
|
|
], function( index, direction ) {
|
|
|
|
element.clone().insertAfter( target ).position({
|
2012-04-10 16:11:28 +00:00
|
|
|
my: "center",
|
|
|
|
at: direction,
|
|
|
|
of: target,
|
2012-04-11 13:20:30 +00:00
|
|
|
using: using
|
2012-04-20 15:18:58 +00:00
|
|
|
});
|
2012-04-10 16:11:28 +00:00
|
|
|
});
|
2012-04-11 13:20:30 +00:00
|
|
|
|
2012-04-20 15:18:58 +00:00
|
|
|
element.width( 150 );
|
2012-10-25 10:39:14 +00:00
|
|
|
function positionWithOffset( horizontal, vertical ) {
|
|
|
|
return {
|
2012-04-11 13:20:30 +00:00
|
|
|
my: "left top",
|
2012-10-25 10:39:14 +00:00
|
|
|
at: "left" + (horizontal < 0 ? horizontal : "+" + horizontal) + " " +
|
|
|
|
"top" + (vertical < 0 ? vertical : "+" + vertical),
|
2012-04-11 13:20:30 +00:00
|
|
|
of: target,
|
|
|
|
using: using
|
2012-04-20 15:18:58 +00:00
|
|
|
};
|
2012-10-25 10:39:14 +00:00
|
|
|
};
|
|
|
|
$( document ).on( "mousemove", function( event ) {
|
|
|
|
element.position( positionWithOffset(
|
|
|
|
event.pageX - targetOffset.left, event.pageY - targetOffset.top ) );
|
|
|
|
oppositeElement.position( positionWithOffset(
|
|
|
|
-1 * (event.pageX - targetOffset.left), -1 * (event.pageY - targetOffset.top) ) );
|
|
|
|
leftElement.position( positionWithOffset(
|
|
|
|
-0.9 * (event.pageX - targetOffset.left), 0.9 * (event.pageY - targetOffset.top) ) );
|
|
|
|
rightElement.position( positionWithOffset(
|
|
|
|
0.9 * (event.pageX - targetOffset.left), -0.9 * (event.pageY - targetOffset.top) ) );
|
2012-04-11 23:32:30 +00:00
|
|
|
});
|
2012-04-10 16:11:28 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<style>
|
2012-04-20 15:18:58 +00:00
|
|
|
#target, .element {
|
|
|
|
position: absolute;
|
|
|
|
border: 1px solid black;
|
|
|
|
border-radius: 5px;
|
|
|
|
width: 75px;
|
|
|
|
height: 25px;
|
|
|
|
padding: 5px;
|
2012-05-21 00:34:21 +00:00
|
|
|
font-size: 62.5%;
|
2012-04-20 15:18:58 +00:00
|
|
|
}
|
|
|
|
#target {
|
|
|
|
height: 75px;
|
|
|
|
}
|
|
|
|
.element:before {
|
|
|
|
font-size: 12pt;
|
|
|
|
content: "↑";
|
|
|
|
position: absolute;
|
|
|
|
top: -19px;
|
|
|
|
left: 5px;
|
|
|
|
}
|
|
|
|
.right:before {
|
|
|
|
left: auto;
|
|
|
|
right: 5px;
|
|
|
|
}
|
|
|
|
.bottom:before {
|
|
|
|
content: "↓";
|
|
|
|
top: auto;
|
|
|
|
bottom: -19px;
|
|
|
|
}
|
|
|
|
.center:before {
|
|
|
|
left: 50%;
|
|
|
|
right: auto;
|
|
|
|
}
|
|
|
|
.middle:before {
|
|
|
|
top: 50%;
|
|
|
|
bottom: auto;
|
|
|
|
}
|
|
|
|
.horizontal:before {
|
|
|
|
height: 10px;
|
|
|
|
top: 50%;
|
|
|
|
margin-top: -8px;
|
|
|
|
bottom: auto;
|
|
|
|
left: -18px;
|
|
|
|
right: auto;
|
|
|
|
content: "←";
|
|
|
|
}
|
|
|
|
.right.horizontal:before {
|
|
|
|
left: auto;
|
|
|
|
right: -18px;
|
|
|
|
content: "→";
|
|
|
|
}
|
|
|
|
.bottom.horizontal:before {
|
|
|
|
top: auto;
|
|
|
|
bottom: 5px;
|
|
|
|
}
|
|
|
|
.top.horizontal:before {
|
|
|
|
top: 5px;
|
|
|
|
}
|
2012-04-10 16:11:28 +00:00
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
2012-04-20 15:18:58 +00:00
|
|
|
<div id="target">all around me</div>
|
|
|
|
<div class="element"></div>
|
2012-04-10 16:11:28 +00:00
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|