Reputation: 237
I have a div in fixed position that i like to make it center of my browser..
Of course it can be done with css, but the thing is i`m changing element's width in several times (loading something by ajax, so the width will change!) ...
So i want centering the div after changing its width by jquery.
For centering i use this code: http://manos.malihu.gr/center-div-with-jquery
But when i changing div's width, it doesn't become in center even after calling CenterItem again!
Bottom line, i want something like this: http://www.dynamicdrive.com/dynamicindex4/lightbox2/index.htm
Upvotes: 0
Views: 999
Reputation: 318342
If using the script in your link, call the Centeritem function on the resize event on the element as well as on the window.
$('#ElementsID').resize(function() {
CenterItem('.centered');
});
Upvotes: 1
Reputation: 6344
Why use JQuery at all? CSS can easily center items, even with variable (and changing) widths.
Upvotes: 3