Last active
October 11, 2017 05:12
-
-
Save shohagbhuiyan/00ae297ddbe92e445f79af81ee79c7d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//It will work for the element that has position: relative | |
function postionMiddle(e) { | |
var capHeightHalf = $(e).innerHeight() / 2, | |
capParentHeightHalf = $(e).parent().innerHeight() / 2, | |
capPosition = capParentHeightHalf - capHeightHalf; | |
$(e).css("top", capPosition ); | |
} | |
postionMiddle(".caption"); // place your element instead .caption | |
//If you want to pass multiple value inside the function or want to plus/minus from the output value | |
/* function postionMiddle(e, v) { | |
var capHeightHalf = $(e).innerHeight() / 2, | |
capParentHeightHalf = $(e).parent().innerHeight() / 2, | |
capPosition = capParentHeightHalf - capHeightHalf; | |
if (v == null){ | |
$(e).css("top", capPosition ); | |
}else{ | |
var capPosition2 = capPosition - v; | |
$(e).css("top", capPosition2 ); | |
} | |
} | |
postionMiddle(".caption"); | |
postionMiddle("nav", 32); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment