Have you ever had to deal with the hassle of centering modal windows? I made this function to automagically center windows I call this function after I load a modal and it centers the object perfectly for every browser. It takes the hassle of wondering if something is perfectly center in every browser. The only thing I do to use it is send it the main containing div that the object should be centered in and the div that I want to be centered. It grabs the offset does a little basic math and that’s it. No more hassle with centering now it will be perfectly centered.
?View Code JAVASCRIPTfunction CenterIT(mainModal, mainContainer) {
var modalW = $(mainModal).width() / 2;
var windowW = $(mainContainer).width() / 2;
var modalH = $(mainModal).height() / 2;
var windowH = $(mainContainer).height() / 2;
var centerPointW = windowW - modalW;
var centerPointH = windowH - modalH;
var myPoint = $(mainContainer).offset();
centerPointW = myPoint.left + centerPointW;
centerPointH = myPoint.top + centerPointH;
$(mainModal).css('left', centerPointW);
$(mainModal).css('top', centerPointH);
}
Some Useful/Interesting Flash Links: Prefab – Highly useful tool when it comes to 3D in flash with Away3D Snook on HTML5 and Adobe Some Useful/Interesting JavaScript Links: Javascript RayCaster Burst Engine for SVG in JavaScript Canvas 3D JS3D library Parallax in CSS WebGL Example Bookmark and Share More »Powered by Bookmarkify™
