Vertical Center

plugin banner

Easily vertically center any element relative to its container in an intelligent, fully responsive way.

Author:Braad Martin (profile at wordpress.org)
WordPress version required:3.8
WordPress version tested:4.4.32
Plugin version:1.1.1
Added to WordPress repository:01-04-2015
Last updated:07-12-2015
Warning! This plugin has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.
Rating, %:100
Rated by:5
Plugin URI:https://wordpress.org/plugins/vertical-center...
Total downloads:4 189
Active installs:100+
plugin download
Click to start download

Vertical Center lets you easily vertically center elements.

Features

  • Center an unlimited number of elements independently
  • Specify simple CSS/jQuery selectors to target elements
  • Easy to use admin interface
  • Items are vertical centered immediately after the page has loaded
  • Adds a class to each centered element after it has been centered (useful for CSS transition effects)
  • Fully responsive (automatically updates on resize and orientationchange events)
  • Works on mobile devices
  • Works across all modern browsers (including IE8)
  • Trigger custom ‘verticalcenter’ event to force a recalculation
  • Debounced resize events for added smoothness

Check out the Screenshots tab for a gif of the plugin in action.

Instructions

  1. Navigate to Settings > Vertical Center in the WordPress admin.
  2. Enter a selector and an offset for the element(s) you want to center.
  3. Add/remove additional elements by clicking the “+ Add More” and “Remove” buttons.

Advanced

Want to trigger the vertical centering manually? No problem. You can skip entering a selector on the settings page and call the jQuery script yourself using either .initVerticalCenter() or .doVerticalCenter(). The .initVerticalCenter() method sets up the event listeners to recalculate if the window is resized, while the .doVerticalCenter() method directly centers without attaching any events:

// Attach events and center.
jQuery( '.selector' ).initVerticalCenter();

// Center without attaching events.
jQuery( '.selector' ).doVerticalCenter();

Both functions take one optional argument, the offset value (as a number of pixels):

jQuery( '.selector' ).initVerticalCenter( offset );

jQuery( '.selector' ).doVerticalCenter( offset );

To offset the calculation by 20 pixels:

jQuery( '.selector' ).initVerticalCenter( 20 );

The functions are chainable. My personal favorite way to use this plugin is to inline style="opacity: 0;" on the elements that I am centering (to guarantee they’ll be transparent when the DOM loads) and then fade them in with something like this:

jQuery( '.selector' ).initVerticalCenter().delay( 200 ).fadeTo( 'slow', 1 );

Or to achieve the same effect with only CSS you can use the vc-complete class that gets added to each target element after the initial centering (added in version 1.0.3), which might look like this:

#target {
    opacity: 0;
    transition: opacity 0.5s;
}

#target.vc-complete {
    opacity: 1;
}

This plugin also adds an event ‘verticalcenter’ to the window, allowing you to easily trigger the vertical centering manually. This is useful if you have added items to the page after it loads via AJAX. You can trigger the event like this:

jQuery( window ).trigger( 'verticalcenter' );

Screenshots
FAQ
ChangeLog