File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*global jQuery */
2
+ /*!
3
+ * FlexVerticalCenter.js 1.0
4
+ *
5
+ * Copyright 2011, Paul Sprangers http://paulsprangers.com
6
+ * Released under the WTFPL license
7
+ * http://sam.zoy.org/wtfpl/
8
+ *
9
+ * Date: Fri Oct 28 19:12:00 2011 +0100
10
+ */
11
+ ( function ( $ ) {
12
+
13
+ $ . fn . flexVerticalCenter = function ( onAttribute ) {
14
+
15
+ return this . each ( function ( ) {
16
+ var $this = $ ( this ) ; // store the object
17
+ var attribute = onAttribute || 'margin-top' ; // the attribute to put the calculated value on
18
+
19
+ // resize to box the maintain the set ratio
20
+ var resizer = function ( ) {
21
+ // get parent height minus own height and devide by 2
22
+ $this . css (
23
+ attribute , ( ( $this . parent ( ) . height ( ) - $this . height ( ) ) / 2 )
24
+ ) ;
25
+ } ;
26
+
27
+ // Call once to set.
28
+ resizer ( ) ;
29
+
30
+ // Call on resize. Opera debounces their resize by default.
31
+ $ ( window ) . resize ( resizer ) ;
32
+
33
+ } ) ;
34
+
35
+ } ;
36
+
37
+ } ) ( jQuery ) ;
You can’t perform that action at this time.
0 commit comments