views:

2408

answers:

1

I have a draggable YUI Panel defined like this

new YAHOO.widget.Panel("parameters", {
                        fixedcenter: true,
                        constraintoviewport: true,
                        underlay: "shadow",
                        visible: false,
                        close: true,
                        draggable: true,
                        width: "350px" });

When the panel is shown, I want it to remain always visible, even when the window is scrolled. This is also the case, thanks to fixedcenter: true. The problem is that when the window is scrolled the panel positions itself to the center of the window even if it was dragged somewhere else previously.

How should I modify the above definition so that the position of the panel remains constant relative to the window when the window is scrolled?

+2  A: 

Wrap your panel container in a wrapper element that has fixed positioning, e.g.

<div id="wrapper" style="position: fixed">
 <div id="parameters">
  <div class="hd">Header</div>
  <div class="bd">Hello, this is my awesome panel.</div>
  <div class="ft">Footer</div>
 </div>
</div>

Construct your panel without the fixedcenter configuration property, and center the panel immediately after you render it, e.g.

var panel = new YAHOO.widget.Panel("parameters", {
  constraintoviewport: true,
  underlay: "shadow",
  visible: false,
  close: true,
  draggable: true,
  width: "350px"
 });
panel.render();
panel.center();

The panel should now stay in the same position when the window is scrolled. I only tested this in Firefox 3.0 and Internet Explorer 7 and 8.

I've posted the source of a self-contained example that will demonstrate this working.

Simon Lieschke
Thanks. This works in Safari 3.2.1 and Opera 10 as well.
Kaarel