Skip to content

Commit db9857e

Browse files
committed
made cssAttribute part of the options hash
1 parent 6e1b2c4 commit db9857e

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ This will take the parents height, the elements own height and calculate the dis
2525
Options
2626
-------
2727

28-
You can pass 1 parameter and an options hash to the plugin.
28+
You can pass an options hash to the plugin.
2929

3030
- `onAttribute` - the css attribute that the value should be set on (default: 'margin-top')
3131
- `verticalOffset` - the number of pixels to offset the vertical alignment by, ie. 10, "50px", -100 (default: 0)
32-
- `parentSelector` - a selector representing the parent to vertically center this element within, ie. ".container" (default: the element's immediate parent)
32+
- `parentSelector` - a selector representing the parent to vertically center this element within, ie. ".parent" (default: the element's immediate parent)
3333

3434
Examples:
3535

3636
<script>
3737
$(document).ready(function() {
38-
$('#element-to-be-centered').flexVerticalCenter('padding-top');
39-
$('#element-to-be-centered').flexVerticalCenter('margin-top', { verticalOffset: 50 });
40-
$('#element-to-be-centered').flexVerticalCenter('padding-top', { verticalOffset: 50, parentSelector: '.parent' });
38+
$('#element-to-be-centered').flexVerticalCenter();
39+
$('#element-to-be-centered').flexVerticalCenter({ cssAttribute: 'padding-top', verticalOffset: '50px' });
40+
$('#element-to-be-centered').flexVerticalCenter({ cssAttribute: 'padding-top', parentSelector: '.parent' });
4141
});
4242
</script>
4343

index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@
6262
<script src="jquery.flexverticalcenter.js"></script>
6363

6464
<script>
65-
$('.first-item').flexVerticalCenter('padding-top');
66-
$('.second-item').flexVerticalCenter('padding-top', { verticalOffset: '50px' });
67-
$('.third-item').flexVerticalCenter('padding-top', { parentSelector: '.parent' });
65+
$('.first-item').flexVerticalCenter({ cssAttribute: 'padding-top' });
66+
$('.second-item').flexVerticalCenter({ cssAttribute: 'padding-top', verticalOffset: '50px' });
67+
$('.third-item').flexVerticalCenter({ cssAttribute: 'padding-top', parentSelector: '.parent' });
6868
</script>
6969
</body>
7070

jquery.flexverticalcenter.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
*/
1111
(function( $ ){
1212

13-
$.fn.flexVerticalCenter = function( onAttribute, options ) {
14-
var attribute = onAttribute || 'margin-top'; // the attribute to put the calculated value on
13+
$.fn.flexVerticalCenter = function( options ) {
1514
var settings = $.extend({
16-
verticalOffset: 0, // the number of pixels to offset the vertical alignment by
17-
parentSelector: null // a selector representing the parent to vertically center this element within
15+
cssAttribute: 'margin-top', // the attribute to apply the calculated value to
16+
verticalOffset: 0, // the number of pixels to offset the vertical alignment by
17+
parentSelector: null // a selector representing the parent to vertically center this element within
1818
}, options || {});
1919

2020
return this.each(function(){
@@ -25,7 +25,7 @@
2525
var parentHeight = (settings.parentSelector) ? $this.parents(settings.parentSelector).first().height() : $this.parent().height();
2626

2727
$this.css(
28-
attribute, ( ( ( parentHeight - $this.height() ) / 2 ) + parseInt(settings.verticalOffset) )
28+
settings.cssAttribute, ( ( ( parentHeight - $this.height() ) / 2 ) + parseInt(settings.verticalOffset) )
2929
);
3030
};
3131

0 commit comments

Comments
 (0)