Skip to content
Permalink
Browse files

release 1.1.1, [bug fixed] center against window failed

  • Loading branch information...
Fred Chu
Fred Chu committed Oct 31, 2012
1 parent 1cf91c4 commit 72408e8ae31ba533f26c976f8a1baca1912adfa4
Showing with 32 additions and 11 deletions.
  1. +6 −0 CHANGELOG.md
  2. +24 −9 jquery.center.js
  3. +2 −2 jquery.center.min.js
@@ -1,5 +1,11 @@
# jQuery Center Plugin CHANGELOG

## 1.1.1/ 2012-10-31

- [bug fix] center against window failed



## 1.1.0

* Add center on window resize option, default to true
@@ -1,17 +1,29 @@
/*! Copyright 2011, Ben Lin (http://dreamerslab.com/)
* Licensed under the MIT License (LICENSE.txt).
*
* Version: 1.1.0
* Version: 1.1.1
*
* Requires: jQuery 1.2.6+
*/
;( function( $, window ){
var get_win_size = function (){
if( window.innerWidth != undefined ){
return [ window.innerWidth, window.innerHeight ];
}else{
var B = document.body;
var D = document.documentElement;

return [ Math.max( D.clientWidth, B.clientWidth ), Math.max( D.clientHeight, B.clientHeight )];
}
}

$.fn.center = function( opt ){
var $w = $( window ); // cache gobal
var scrollTop = $w.scrollTop();

return this.each( function(){
var $this = $( this ); // cache $( this )

// merge user options with default configs
var configs = $.extend({
against : 'window',
@@ -22,26 +34,29 @@

var centerize = function(){
var against = configs.against;
var against_w_n_h;
var $against;

if( against === 'window' ){
$against = $w;
against_w_n_h = get_win_size();
}else if( against === 'parent' ){
$against = $this.parent();
scrollTop = 0;
$against = $this.parent();
against_w_n_h = [ $against.width(), $against.height()];
scrollTop = 0;
}else{
$against = $this.parents( against );
scrollTop = 0;
$against = $this.parents( against );
against_w_n_h = [ $against.width(), $against.height()];
scrollTop = 0;
}

var x = (( $against.width()) - ( $this.outerWidth())) * 0.5;
var y = (( $against.height()) - ( $this.outerHeight())) * configs.topPercentage + scrollTop;
var x = (( against_w_n_h[ 0 ]) - ( $this.outerWidth())) * 0.5;
var y = (( against_w_n_h[ 1 ]) - ( $this.outerHeight())) * configs.topPercentage + scrollTop;

if( configs.top ) y = configs.top + scrollTop;

$this.css({
'left' : x,
'top' : y
'top' : y
});
};

Some generated files are not rendered by default. Learn more.

0 comments on commit 72408e8

Please sign in to comment.
You can’t perform that action at this time.