Update 2017
Since I just received another answer to this answer, I decided to return to it.
In modern browsers, you are lucky with the conversion technique (-50%, -50%) from other answers, but depending on how your content containers are configured, which may not lead to the center of the window; it may be the center of your container, which may be smaller or larger than the window.
Recent browsers support view units (vh, vw) that will give you exactly what you are looking for, before centering the viewport. Animation from the current location to the center of the viewport would be another problem due to scrolling.
http://caniuse.com/#feat=viewport-units https://developer.mozilla.org/en-US/docs/Web/CSS/length (see vh, vw)
No CSS Transformation
You can do this without using css-transform using absolute positioning:
(full code here: http://jsfiddle.net/wkgWg/ )
.posDiv { position:absolute; top:0; left:0; margin:0; border:1px solid red; -moz-transition:all 2s; -webkit-transition:all 2s; -o-transition:all 2s; transition:all 2s; } .triggerElement:hover .posDiv { top:50%; left:50%; margin-left:-50px; margin-top:-50px; -moz-transition:all 2s; -webkit-transition:all 2s; -o-transition:all 2s; transition:all 2s; }
Using CSS Transform
If you want to continue working with the CSS transform, you need to calculate the "center" or final location of the transform using JavaScript, and then generate and attach the transform operator at run time. Your original transform vector must be subtracted from the center-to-screen vector.
Here's a javascript version using css-transform (where supported) through the jQuery.transit plugin from Rico Sta. Cruz .
(Full fiddle here: http://jsfiddle.net/ZqpGL/263/ )
$(function() { var $cards = $('.card'); var cardInFocus = null; $cards.each(function(index, elem) { var $elem = $(elem); var pos = $elem.position(); $(elem).data('orig-x', pos.left); $(elem).data('orig-y', pos.top); }); var reset = function() { if (cardInFocus) { $(cardInFocus).transition({ x: 0, y: 0 }); } }; $cards.on('focus', function(e) { reset(); cardInFocus = this; var $doc = $(document); var centerX = $doc.width() / 2; var centerY = $doc.height() / 2; var $card = $(this); var origX = $card.data('orig-x'); var origY = $card.data('orig-y'); $(this).transition({ x: centerX - origX, y: centerY - origY }); }); $cards.on('blur', function(e) { reset(); }); });