-
28 Aug 2012 3:19 AM #1
Answered: Find center co-ordinates of browser / Viewport
Answered: Find center co-ordinates of browser / Viewport
Hello Guys,
Iam displaying a pop-up wiondow, and want it to display always at the center even if i re-size the browser. I have used the .center method , which is not working if i re-size the browser. I want to get X, Y co-ordinates of the browser and to the window x , y property want to set it.
Any help would be appriciated,
Thanks,
-
Best Answer Posted by friend
Take a look at Ext.EventManager.onWindowResize().
I typically register my Window with the EventManager in the Window's afterrender event, then remove the listener before close. Here's a functional example, where you can substitute the centerMe() function for a globally scoped/shared function for efficiency.
Code:Ext.create('Ext.window.Window', { height: 200, title: 'Auto-centering Window', width: 200, centerMe: function() { this.center(); }, listeners: { afterrender: function(component, eOpts) { Ext.EventManager.onWindowResize(this.centerMe, component); }, beforeclose: function(component, eOpts) { Ext.EventManager.removeResizeListener(this.centerMe, component); } } }).show();
-
28 Aug 2012 3:29 AM #2Sencha - Community Support Team
- Join Date
- May 2012
- Location
- Istanbul
- Posts
- 1,331
- Vote Rating
- 76
- Answers
- 124
sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.
-
28 Aug 2012 6:02 AM #3
Hi i checked the link you gave but the results are not accurate, when i use the code..... could you suggest as to what may be the problem. when i run the code on my monitor i get the x = 347.5 and Y = 576 , but this is not the center co-ordinates....of my monitor
-
28 Aug 2012 6:20 AM #4
Center method works for me:
live http://jsfiddle.net/LTv7E/1/Code:var win = Ext.create('Ext.window.Window', { title: 'Hello', height: 200, width: 400, layout: 'fit', items: { xtype: 'grid', border: false, columns: [{header: 'World'}], store: Ext.create('Ext.data.ArrayStore', {}) } }).show(); Ext.EventManager.onWindowResize(function () { win.center(); });
-
28 Aug 2012 6:24 AM #5
Take a look at Ext.EventManager.onWindowResize().
I typically register my Window with the EventManager in the Window's afterrender event, then remove the listener before close. Here's a functional example, where you can substitute the centerMe() function for a globally scoped/shared function for efficiency.
Code:Ext.create('Ext.window.Window', { height: 200, title: 'Auto-centering Window', width: 200, centerMe: function() { this.center(); }, listeners: { afterrender: function(component, eOpts) { Ext.EventManager.onWindowResize(this.centerMe, component); }, beforeclose: function(component, eOpts) { Ext.EventManager.removeResizeListener(this.centerMe, component); } } }).show();
-
28 Aug 2012 9:48 PM #6


Reply With Quote