Position visual tests: Cleanup.

This commit is contained in:
Scott González 2012-04-20 11:18:58 -04:00
parent 308b55e50c
commit af1576280a
2 changed files with 143 additions and 138 deletions

View File

@ -1,19 +1,19 @@
<!DOCTYPE html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="utf-8">
<title>Position Visual Test: Default</title> <title>Position Visual Test: Default</title>
<link rel="stylesheet" href="../visual.css" type="text/css" /> <link rel="stylesheet" href="../visual.css">
<link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css" type="text/css" title="ui-theme" /> <link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css">
<script type="text/javascript" src="../../../jquery-1.7.2.js"></script> <script src="../../../jquery-1.7.2.js"></script>
<script type="text/javascript" src="../../../ui/jquery.ui.core.js"></script> <script src="../../../ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="../../../ui/jquery.ui.widget.js"></script> <script src="../../../ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../../../ui/jquery.ui.position.js"></script> <script src="../../../ui/jquery.ui.position.js"></script>
<script type="text/javascript" src="../../../ui/jquery.ui.menu.js"></script> <script src="../../../ui/jquery.ui.menu.js"></script>
<script type="text/javascript"> <script>
$(function() { $(function() {
function using( position, feedback ) { function using( position, feedback ) {
$(this) $( this )
.css( position ) .css( position )
.text( feedback.horizontal + " " + feedback.vertical + " " + feedback.important ) .text( feedback.horizontal + " " + feedback.vertical + " " + feedback.important )
.removeClass( "left right top bottom center middle vertical horizontal" ) .removeClass( "left right top bottom center middle vertical horizontal" )
@ -21,12 +21,18 @@
.addClass( feedback.vertical ) .addClass( feedback.vertical )
.addClass( feedback.important ); .addClass( feedback.important );
} }
var target = $("#target").position({
var element = $( ".element" ),
target = $( "#target" ).position({
my: "center", my: "center",
at: "center", at: "center",
of: window of: window
}); }),
var element = $(".element"); 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([ $.each([
"center top-100", "center top-100",
"right+25 top-50", "right+25 top-50",
@ -40,39 +46,35 @@
"left-75 center", "left-75 center",
"left-75 top", "left-75 top",
"left-25 top-50" "left-25 top-50"
], function(index, direction) { ], function( index, direction ) {
element.clone().insertAfter(target).position({ element.clone().insertAfter( target ).position({
my: "center", my: "center",
at: direction, at: direction,
of: target, of: target,
using: using using: using
}) });
}); });
var targetOffset = target.offset(); element.width( 150 );
var oppositeElement = element.clone().width(50).appendTo('body'); $( document ).on( "mousemove", function( event ) {
var leftElement = element.clone().width(50).height(150).appendTo('body');
var rightElement = element.clone().height(150).width(150).appendTo('body');
element.width(150);
$(document).on( "mousemove", function(event) {
var base = { var base = {
my: "left top", my: "left top",
at: "left top", at: "left top",
of: target, of: target,
using: using using: using
} };
element.position( $.extend({ element.position( $.extend({
offset: (event.pageX - targetOffset.left) + " " + (event.pageY - targetOffset.top) offset: (event.pageX - targetOffset.left) + " " + (event.pageY - targetOffset.top)
}, base)); }, base ));
oppositeElement.position( $.extend({ oppositeElement.position( $.extend({
offset: (-1 * (event.pageX - targetOffset.left)) + " " + (-1 * (event.pageY - targetOffset.top)) offset: (-1 * (event.pageX - targetOffset.left)) + " " + (-1 * (event.pageY - targetOffset.top))
}, base)); }, base ));
leftElement.position( $.extend({ leftElement.position( $.extend({
offset: (-0.9 * (event.pageX - targetOffset.left)) + " " + (0.9 * (event.pageY - targetOffset.top)) offset: (-0.9 * (event.pageX - targetOffset.left)) + " " + (0.9 * (event.pageY - targetOffset.top))
}, base)); }, base ));
rightElement.position( $.extend({ rightElement.position( $.extend({
offset: (0.9 * (event.pageX - targetOffset.left)) + " " + (-0.9 * (event.pageY - targetOffset.top)) offset: (0.9 * (event.pageX - targetOffset.left)) + " " + (-0.9 * (event.pageY - targetOffset.top))
}, base)); }, base) );
}); });
}); });
</script> </script>
@ -137,9 +139,8 @@
</head> </head>
<body> <body>
<div id="target">all around me</div> <div id="target">all around me</div>
<div class="element"></div>
<div class="element"></div>
</body> </body>
</html> </html>

View File

@ -1,22 +1,25 @@
<!DOCTYPE html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="utf-8">
<title>Position Visual Test: Default</title> <title>Position Visual Test: Default</title>
<link rel="stylesheet" href="../visual.css" type="text/css" /> <link rel="stylesheet" href="../visual.css">
<link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css" type="text/css" title="ui-theme" /> <link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css">
<script type="text/javascript" src="../../../jquery-1.7.2.js"></script> <script src="../../../jquery-1.7.2.js"></script>
<script type="text/javascript" src="../../../ui/jquery.ui.core.js"></script> <script src="../../../ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="../../../ui/jquery.ui.widget.js"></script> <script src="../../../ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../../../ui/jquery.ui.position.js"></script> <script src="../../../ui/jquery.ui.position.js"></script>
<script type="text/javascript" src="../../../ui/jquery.ui.menu.js"></script> <script src="../../../ui/jquery.ui.menu.js"></script>
<script type="text/javascript"> <script>
$(function() { $(function() {
function using( position, feedback ) { function using( position, feedback ) {
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; var angleRad = Math.atan2(
var angle = (Math.round( angleRad * 100) / 100 ); feedback.target.top + feedback.target.height / 2 - feedback.element.top - feedback.element.height / 2,
$(this) feedback.target.left + feedback.target.width / 2 - feedback.element.left - feedback.element.width / 2
.offset( position ) ) * 180 / Math.PI,
angle = Math.round( angleRad * 100) / 100;
$( this )
.css( position )
.text( feedback.horizontal + " " + feedback.vertical + " " + feedback.important + " " + angle + "°" ) .text( feedback.horizontal + " " + feedback.vertical + " " + feedback.important + " " + angle + "°" )
.css({ .css({
"-webkit-transform": "rotate(" + angle + "deg)", "-webkit-transform": "rotate(" + angle + "deg)",
@ -26,12 +29,18 @@
"transform": "rotate(" + angle + "deg)" "transform": "rotate(" + angle + "deg)"
}); });
} }
var target = $("#target").position({
var element = $( ".element" ),
target = $( "#target" ).position({
my: "center", my: "center",
at: "center", at: "center",
of: window of: window
}); }),
var element = $(".element"); 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([ $.each([
"center top-100", "center top-100",
"right+25 top-50", "right+25 top-50",
@ -45,39 +54,35 @@
"left-75 center", "left-75 center",
"left-75 top", "left-75 top",
"left-25 top-50" "left-25 top-50"
], function(index, direction) { ], function( index, direction ) {
element.clone().insertAfter(target).position({ element.clone().insertAfter( target ).position({
my: "center", my: "center",
at: direction, at: direction,
of: target, of: target,
using: using using: using
}) });
}); });
var targetOffset = target.offset(); element.width( 150 );
var oppositeElement = element.clone().width(50).appendTo('body'); $( document ).on( "mousemove", function( event ) {
var leftElement = element.clone().width(50).height(150).appendTo('body');
var rightElement = element.clone().height(150).width(150).appendTo('body');
element.width(150);
$(document).on( "mousemove", function(event) {
var base = { var base = {
my: "left top", my: "left top",
at: "left top", at: "left top",
of: target, of: target,
using: using using: using
} };
element.position( $.extend({ element.position( $.extend({
offset: (event.pageX - targetOffset.left) + " " + (event.pageY - targetOffset.top) offset: (event.pageX - targetOffset.left) + " " + (event.pageY - targetOffset.top)
}, base)); }, base ));
oppositeElement.position( $.extend({ oppositeElement.position( $.extend({
offset: (-1 * (event.pageX - targetOffset.left)) + " " + (-1 * (event.pageY - targetOffset.top)) offset: (-1 * (event.pageX - targetOffset.left)) + " " + (-1 * (event.pageY - targetOffset.top))
}, base)); }, base ));
leftElement.position( $.extend({ leftElement.position( $.extend({
offset: (-0.9 * (event.pageX - targetOffset.left)) + " " + (0.9 * (event.pageY - targetOffset.top)) offset: (-0.9 * (event.pageX - targetOffset.left)) + " " + (0.9 * (event.pageY - targetOffset.top))
}, base)); }, base ));
rightElement.position( $.extend({ rightElement.position( $.extend({
offset: (0.9 * (event.pageX - targetOffset.left)) + " " + (-0.9 * (event.pageY - targetOffset.top)) offset: (0.9 * (event.pageX - targetOffset.left)) + " " + (-0.9 * (event.pageY - targetOffset.top))
}, base)); }, base ));
}); });
}); });
</script> </script>
@ -97,9 +102,8 @@
</head> </head>
<body> <body>
<div id="target">all around me</div> <div id="target">all around me</div>
<div class="element"></div>
<div class="element"></div>
</body> </body>
</html> </html>