views:

4696

answers:

1

Hi there,

Anyone have any experience with jquery vAligh plugins or similar?

I tried to align for the following but it fails.. I was using a simple valign plugin (I will put the plugin at the end, its a jquery extension), if anyone can help it would be really helpful...

var overlayLayer = $("<div id='office-location'></div>").addClass('modal-overlay');
$('body').append(overlayLayer);

$('<div id="content-for-overlay" style="background-color: white;"></div>').appendTo(overlayLayer);

this.render({ to: "content-for-overlay", partial: "office-location-modal" }); // this just copies html into the layer

$('#content-for-overlay').vAlign(); THIS USES a plugin called valign but it doesn't align

$("body").css("overflow", "hidden");
$('#office-location').css("opacity", 0.8).fadeIn(150);
$('#content-for-overlay').css("opacity", 1);

heres the FN extension..

(function($) {
$.fn.vAlign = function() {
    return this.each(function(i) {
        var h = $(this).height();
        var oh = $(this).outerHeight();
        var mt = (h + (oh - h)) / 2;
        $(this).css("margin-top", "-" + mt + "px");
        $(this).css("top", "50%");
        $(this).css("position", "absolute");
    });
};

})(jQuery);

+2  A: 

You could try using a CSS technique to vertically centre items, as shown here. I believe the method is cross-browser, though unfortunately it adds an extra div to your markup.

It'd be fairly easy to apply this css to the markup using jQuery, using $().css()

Donald Harvey
http://stackoverflow.com/questions/967022/how-do-i-vertical-center-text-next-to-an-image-in-html-css has a discussion that's relevant, too.
ajm