jquery-ui/tests/visual/position/position_feedback_rotate.html

110 lines
3.1 KiB
HTML
Raw Normal View History

2012-04-20 15:18:58 +00:00
<!doctype html>
<html lang="en">
<head>
2012-04-20 15:18:58 +00:00
<meta charset="utf-8">
<title>Position Visual Test: Default</title>
2012-04-20 15:18:58 +00:00
<link rel="stylesheet" href="../visual.css">
<link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css">
<script src="../../../jquery-1.7.2.js"></script>
<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>
$(function() {
function using( position, feedback ) {
2012-04-20 15:18:58 +00:00
var angleRad = Math.atan2(
feedback.target.top + feedback.target.height / 2 - feedback.element.top - feedback.element.height / 2,
feedback.target.left + feedback.target.width / 2 - feedback.element.left - feedback.element.width / 2
) * 180 / Math.PI,
angle = Math.round( angleRad * 100) / 100;
$( this )
.css( position )
.text( feedback.horizontal + " " + feedback.vertical + " " + feedback.important + " " + angle + "°" )
.css({
"-webkit-transform": "rotate(" + angle + "deg)",
"-moz-transform": "rotate(" + angle + "deg)",
"-ms-transform": "rotate(" + angle + "deg)",
"-o-transform": "rotate(" + angle + "deg)",
"transform": "rotate(" + angle + "deg)"
});
}
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" );
$.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({
my: "center",
at: direction,
of: target,
using: using
2012-04-20 15:18:58 +00:00
});
});
2012-04-20 15:18:58 +00:00
element.width( 150 );
$( document ).on( "mousemove", function( event ) {
var base = {
my: "left top",
at: "left top",
of: target,
using: using
2012-04-20 15:18:58 +00:00
};
element.position( $.extend({
offset: (event.pageX - targetOffset.left) + " " + (event.pageY - targetOffset.top)
2012-04-20 15:18:58 +00:00
}, base ));
oppositeElement.position( $.extend({
offset: (-1 * (event.pageX - targetOffset.left)) + " " + (-1 * (event.pageY - targetOffset.top))
2012-04-20 15:18:58 +00:00
}, base ));
leftElement.position( $.extend({
offset: (-0.9 * (event.pageX - targetOffset.left)) + " " + (0.9 * (event.pageY - targetOffset.top))
2012-04-20 15:18:58 +00:00
}, base ));
rightElement.position( $.extend({
offset: (0.9 * (event.pageX - targetOffset.left)) + " " + (-0.9 * (event.pageY - targetOffset.top))
2012-04-20 15:18:58 +00:00
}, base ));
});
});
</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;
}
#target {
height: 75px;
}
</style>
</head>
<body>
2012-04-20 15:18:58 +00:00
<div id="target">all around me</div>
<div class="element"></div>
</body>
</html>