node-align.html revision 99030181384118f852c69f20f3b931bf796ec8fa
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Extended XY Positioning</title>
<style type="text/css">
/*margin and padding on body element
can introduce errors in determining
element position and are not recommended;
we turn them off as a foundation for YUI
CSS treatments. */
body {
margin:0 auto;
padding:0;
width: 50em;
}
#test-bleed {
text-align: center;
margin: auto;
}
</style>
<link type="text/css" rel="stylesheet" href="/build/cssfonts/fonts-min.css" />
<script type="text/javascript" src="/build/yui/yui-min.js"></script>
<!--begin custom header content for this example-->
<style type="text/css">
/* Overlay Look/Feel */
.yui-overlay-content {
padding:2px;
border:1px solid #000;
background-color:#aaa;
font-size:93%;
width: 10em;
}
.yui-overlay-content .yui-widget-hd {
font-weight:bold;
text-align:center;
padding:2px;
border:2px solid #aa0000;
background-color:#fff;
}
.yui-overlay-content .yui-widget-bd {
text-align:left;
height: 5em;
padding:2px;
border:2px solid #0000aa;
background-color:#fff;
}
/* Example Layout CSS */
#overlay-align {
border: 1px solid green;
}
.overlay-example {
position:relative;
border:1px solid #000;
background-color:#eee;
padding:5px;
height:25em;
}
.overlay-example button {
margin-left:1px;
}
.overlay-example .filler {
color:#999;
}
.align-box {
height:12em;
width:12em;
border:1px solid #000;
margin:0px;
text-align:center;
}
.align-box .title {
font-weight:bold;
color:#fff;
padding:2px;
}
#align1 {
position:static;
background-color:#0000cc;
}
#align2 {
position:relative;
top:-130px;
left:250px;
background-color:#00cc00;
}
#align3 {
position:absolute;
bottom:130px;
right:20px;
background-color:#cc0000;
}
#alignment {
padding:5px;
display:inline;
background-color:#fff;
border:1px solid black;
}
#step {
font-size:85%;
margin-left:5px;
}
</style>
<!--end custom header content for this example-->
</head>
<body class=" yui-skin-sam">
<h1>Extended XY Positioning</h1>
<div class="exampleIntro">
This example shows how you can use Overlay's extended positioning support to align or center the overlay either in the viewport or relative to another node on the page. You can specify any one of 9 points (top-left, top-right, bottom-left, bottom-right, top-center, bottom-center, left-center, right-center, center) to align on both the Overlay and the node/viewport it is being aligned to.
</div>
<div id="demo">
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->
<div class="overlay-example" id="overlay-align">
<p><pre id="alignment"></pre><span id="step"></span></p>
<p><button type="button" id="align">Next Alignment</button></p>
<p class="filler">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nunc pretium quam eu mi varius pulvinar. Duis orci arcu, ullamcorper sit amet, luctus ut, interdum ac, quam. Pellentesque euismod. Nam tincidunt, purus in ultrices congue, urna neque posuere arcu, aliquam tristique purus sapien id nulla. Etiam rhoncus nulla at leo. Cras scelerisque nisl in nibh. Sed eget odio. Morbi elit elit, porta a, convallis sit amet, rhoncus non, felis. Mauris nulla pede, pretium eleifend, porttitor at, rutrum id, orci. Quisque non urna. Nulla aliquam rhoncus est.</p>
<form id="test-bleed">
<select><option>foo</option></select>
</form>
<div id="align1" class="align-box"><span class="title">id = #align1</span></div>
<div id="align2" class="align-box"><span class="title">id = #align2</span></div>
<div id="align3" class="align-box"><span class="title">id = #align3</span></div>
<div class="yui-overlay-content yui-widget-stdmod">
<div class="yui-widget-hd">Aligned Overlay</div>
<div class="yui-widget-bd">Click the 'Align Next' button to try a new alignment</div>
</div>
</div>
<script type="text/javascript">
YUI().use("node", "align-plugin", "shim-plugin", function(Y) {
var alignment = Y.one("#alignment"),
stepNumber = Y.one("#step"),
ie = Y.UA.ie,
ie6 = ie && ie < 7,
useShim = (ie6 || (ie && document.compatMode === 'backCompat')),
node = Y.one("#overlay-align .yui-overlay-content")
.plug(Y.Plugin.Align);
if (useShim) {
node.plug(Y.Plugin.Shim);
}
var steps = [
function() {
/* Center in #overlay-align */
node.align.center('#overlay-align');
alignment.setContent("node.align.center('#overlay-align'))");
},
function() {
/* Align top-left corner of overlay, with top-right corner of #align1 */
node.align.to('#align1', 'tr');
alignment.setContent("node.align.to(Y.one('#align1'), 'tr')");
},
function() {
/* Center overlay in #align2 */
node.align.center('#align2');
alignment.setContent("node.align.center('#align2')");
},
function() {
/* Align right-center edge of overlay with right-center edge of viewport */
node.align.to('window', 'rc', 'rc');
alignment.setContent("node.align.to('window', 'rc', 'rc')");
},
function() {
/* Align right-center edge of overlay with right-center edge of viewport
and fix position */
node.align.to('window', 'rc', 'rc', true);
alignment.setContent("node.align.to('window', 'rc', 'rc', true)" +
" (fixed position)");
},
function() {
/* Center overlay in viewport */
node.align.center('window');
alignment.setContent("node.align.center('window')");
},
function() {
/* Center overlay in viewport and fix position */
node.align.center('window', true);
alignment.setContent("node.align.center('window', true)" +
" (fixed position)");
},
function() {
/* Align top-center edge of overlay with bottom-center edge of #align3 */
node.align.to('#align3', 'bc', 'tc');
alignment.setContent("node.align.to('#align3'), 'bc', 'tc')");
}
];
var step = 0;
var totalSteps = steps.length;
function alignNext() {
stepNumber.setContent("Alignment " + (step+1) + " of " + totalSteps);
steps[step]();
step = (++step)%(totalSteps);
}
alignNext();
Y.on("click", alignNext, "#align");
});
</script>
</body>
</html>