mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Position visual tests: Cleanup.
This commit is contained in:
parent
308b55e50c
commit
af1576280a
@ -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({
|
|
||||||
my: "center",
|
var element = $( ".element" ),
|
||||||
at: "center",
|
target = $( "#target" ).position({
|
||||||
of: window
|
my: "center",
|
||||||
});
|
at: "center",
|
||||||
var element = $(".element");
|
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([
|
$.each([
|
||||||
"center top-100",
|
"center top-100",
|
||||||
"right+25 top-50",
|
"right+25 top-50",
|
||||||
@ -40,106 +46,101 @@
|
|||||||
"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>
|
||||||
<style>
|
<style>
|
||||||
#target, .element {
|
#target, .element {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
width: 75px;
|
width: 75px;
|
||||||
height: 25px;
|
height: 25px;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
#target {
|
#target {
|
||||||
height: 75px;
|
height: 75px;
|
||||||
}
|
}
|
||||||
.element:before {
|
.element:before {
|
||||||
font-size: 12pt;
|
font-size: 12pt;
|
||||||
content: "↑";
|
content: "↑";
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: -19px;
|
top: -19px;
|
||||||
left: 5px;
|
left: 5px;
|
||||||
}
|
}
|
||||||
.right:before {
|
.right:before {
|
||||||
left: auto;
|
left: auto;
|
||||||
right: 5px;
|
right: 5px;
|
||||||
}
|
}
|
||||||
.bottom:before {
|
.bottom:before {
|
||||||
content: "↓";
|
content: "↓";
|
||||||
top: auto;
|
top: auto;
|
||||||
bottom: -19px;
|
bottom: -19px;
|
||||||
}
|
}
|
||||||
.center:before {
|
.center:before {
|
||||||
left: 50%;
|
left: 50%;
|
||||||
right: auto;
|
right: auto;
|
||||||
}
|
}
|
||||||
.middle:before {
|
.middle:before {
|
||||||
top: 50%;
|
top: 50%;
|
||||||
bottom: auto;
|
bottom: auto;
|
||||||
}
|
}
|
||||||
.horizontal:before {
|
.horizontal:before {
|
||||||
height: 10px;
|
height: 10px;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
margin-top: -8px;
|
margin-top: -8px;
|
||||||
bottom: auto;
|
bottom: auto;
|
||||||
left: -18px;
|
left: -18px;
|
||||||
right: auto;
|
right: auto;
|
||||||
content: "←";
|
content: "←";
|
||||||
}
|
}
|
||||||
.right.horizontal:before {
|
.right.horizontal:before {
|
||||||
left: auto;
|
left: auto;
|
||||||
right: -18px;
|
right: -18px;
|
||||||
content: "→";
|
content: "→";
|
||||||
}
|
}
|
||||||
.bottom.horizontal:before {
|
.bottom.horizontal:before {
|
||||||
top: auto;
|
top: auto;
|
||||||
bottom: 5px;
|
bottom: 5px;
|
||||||
}
|
}
|
||||||
.top.horizontal:before {
|
.top.horizontal:before {
|
||||||
top: 5px;
|
top: 5px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</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>
|
||||||
|
@ -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({
|
|
||||||
my: "center",
|
var element = $( ".element" ),
|
||||||
at: "center",
|
target = $( "#target" ).position({
|
||||||
of: window
|
my: "center",
|
||||||
});
|
at: "center",
|
||||||
var element = $(".element");
|
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([
|
$.each([
|
||||||
"center top-100",
|
"center top-100",
|
||||||
"right+25 top-50",
|
"right+25 top-50",
|
||||||
@ -45,61 +54,56 @@
|
|||||||
"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>
|
||||||
<style>
|
<style>
|
||||||
#target, .element {
|
#target, .element {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
width: 75px;
|
width: 75px;
|
||||||
height: 25px;
|
height: 25px;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
#target {
|
#target {
|
||||||
height: 75px;
|
height: 75px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</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>
|
||||||
|
Loading…
Reference in New Issue
Block a user