I have the following code:
HTML:
<div id="my-div"></div>
CSS:
#my-div{
display: none;
position: absolute;
left: 150vh;
bottom: -150px;
}
jQuery:
$.fn.vhLeft = function(property,unit){
var wpx = this.css(property).replace(/[^0-9]+/g,"");
var temp = $('<div />').css({
left:'1'+unit,
position: 'absolute'
});
$('body').append(temp);
var oneEm = temp.css(property).replace(/[^0-9]+/g,"");
temp.remove();
var value = wpx/oneEm;
return (Math.round(value*100))+unit;
};
// You could now get your value like
alert($('#my-div').parseInt(vhLeft)('left','vh'));
With credits to @Zword.
First off it seems theres something wrong with the function. With some values it works, with some values it doesnt return the right value.
Example with 150vh, working correct.
Example with 140vh, not working correct.
Basically what i need is to be able to add or subtract 12
to/off the current vh
value for the left
property of #my-div
on click of an element.