PDA

View Full Version : Centered DHTML Window widget: reposition on browser resize?



criszero
08-16-2007, 05:09 PM
1) Script Title: DHTML Window widget (v1.03)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/index.htm

3) Describe problem: Is it possible to extend/modify the script which centers the popup, so that if a user resizes the browser window the popup automatically repositions itself to remain in the centre of the browser window?

I'm not a great coder so please be gentle. LOVE the widget!

ddadmin
08-16-2007, 07:33 PM
Sure, inside the .js file, try finding the line and add to it:


t.isResize(getValue("resize")) //Set whether window is resizable
this.addEvent(window, function(){t.moveTo(xpos, ypos)}, "resize")

The code in red is new.

criszero
08-17-2007, 08:22 AM
That's great! Thanks ddadmin. Now I know this is going to sound greedy, but is there any way this repositioning can be done on the fly ie. the popup moves AS the user resizes the browser window, as opposed to when the browser resizing stops! Really grateful, either way!

ddadmin
08-17-2007, 09:08 AM
Hmmm there may be a way, but I can just imagine the unnecessary complexity in coding required and the number of things that can go wrong. You may have a situation where the browser calls dhtmlwindow.moveTo() incesssantly in a loop. Right now all I'm doing is relying on the onresize event handler, which is as efficient and stable as it gets. :)

criszero
08-17-2007, 09:30 AM
Thanks for the help dd. I think I've been getting a little ahead of myself with coding! I've managed to find a solution showing and hiding a div which pulls in external content and uses margin:auto to centralize. Loving the DD site though. Lots to explore!