brandonjacoby / Midway.js

Automatically center responsive elements.
240 stars 48 forks source link

I'm getting the error where the element won't center till I resize the window. #2

Closed fluke closed 11 years ago

brandonjacoby commented 11 years ago

Can you give me a link to where the problem is please?

fluke commented 11 years ago

Unfortunately its on local server. I'm using Bootstrap and I've used centerHorizontal on the nav.

brandonjacoby commented 11 years ago

Make sure that the element is being centered is set to display: inline; The midway.js file automatically adds that, but sometimes the users CSS can override it.

fluke commented 11 years ago

I made a change and it started working. Don't understand why it works now.

I changed: $(window).load(function() { Midway(); $(window).on('resize', Midway); });

to

$(window).load(function() { Midway(); $(window).on('resize', Midway); Midway(); });

brandonjacoby commented 11 years ago

Hm yeah that's weird, I will look into this more, and why that made it work. Glad you got it sorted nonetheless.

fluke commented 11 years ago

Just to answer your previous question. Display:inline was set on the element. And I found that Midway wasn't working on it's first try but after resizing it worked. So I tried calling it twice just in case running twice was the issue. And it worked.

etcook commented 11 years ago

Out of curiosity, why do you have your onresize listener nested within your onload?