tags:

views:

285

answers:

3

Hi all, I have problems with my layout, when I resize window manually and restore it to normal everything is in the perfect place.

My question is following, is it possible to trick browser and do something with javascript that would actually make browser thing that page has been resized so that my layout looks as it should? some kind of javascipt hack ?

Thank you

UPDATE:

Can I resize and restore window so that user barely notices ?

A: 

toggle the display attribute on the areas that need to be redrawn. for example:

var toDraw = document.getElementById('redrawme');
toDraw.style.display = none;
toDraw.style.display = '';

I dont know whqt the result would be if you tried to do the entire body element as ive never tired it before.

What are you doing that you need to force a redraw?

prodigitalson
Hmm the problem is following, I have left sidebar and central div , onclick I made it so that central div takes the its own space + left sidebar space, after that resize is needed to fix stuff back to normal
Gandalf StormCrow
how are your columns laid out? its probably your layout that needs fixed as suggested above. personally id float them both left in side a wrapper with a clearfix on it and modify from there. Since theyd both be in document flow that should fix the issues youre having i would think.
prodigitalson
they are floated left .. what you mean by clearfix
Gandalf StormCrow
http://www.quirksmode.org/css/clearing.html - Auto Methodhttp://www.positioniseverything.net/easyclearing.html - pseudo class method
prodigitalson
Can you post the relvent parts of you layout and css?
prodigitalson
I already did.. http://stackoverflow.com/questions/1859559/trying-to-change-width-on-click
Gandalf StormCrow
ok added a comment there will echo the same here: Given that content is floated isnt a percentage based width going to be calculated from the last parent element in the hierarchy that is given a hard width or if none its intrinsic width?What happens if you give #contentholder a hard width in px/pt/cm or alternately use one of the former units in your dynmic width assignment for content?
prodigitalson
A: 

You can resize the window like this...

window.resizeTo(width, height);

And if you need to trigger the event handler, you can do that like this...

window.onresize();
Josh Stodola
hmm can I manually fire the onresize event while firing my event?
Gandalf StormCrow
Just like it says in my answer: `window.onresize();`
Josh Stodola
+1  A: 

This is possible with Mootools (which means it can be done without a framework as well), here's an example:

window.addEvent('domready', function() {
 window.addEvent('resize', function() {
  alert('f');
 });
 (function() {
  window.fireEvent('resize');
 }).delay(3000);
});

3 seconds after the DOM-structure has loaded, the resize-event will be fired for the window-object.

Edit;

I have no clue how Mootools solves their fireEvent for the resize event. I tried Google, but found nada. You can of course resize the window manually, but this is really a hack:

function fireOnResizeEvent() {
 var width, height;

 if (navigator.appName.indexOf("Microsoft") != -1) {
  width  = document.body.offsetWidth;
  height = document.body.offsetHeight;
 } else {
  width  = window.outerWidth;
  height = window.outerHeight;
 }

 window.resizeTo(width - 1, height);
 window.resizeTo(width + 1, height);
}

window.onresize = function() {
 alert("Resized!");
}
Björn
Thank you bjorn.. I'm currently googling solution for ordinary javascrpt
Gandalf StormCrow
Nothing yet, how bout if I resize/restore really fast is that possible?
Gandalf StormCrow
Sorry Björn I had some other projects to attend to .. I guess its working .. I'll accept your answer for now (didn't have time to test it). thank you
Gandalf StormCrow