//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