I have a small problem with a javascript calculation. I have a function like this:
$( "#main-nav li[class]" ).each(function( index ) {
var position = $(this).offset();
var width = $(this).width();
var center = parseInt(position) - (parseInt(width) / 2);
console.log("Position: " + position.left + ", width: " + width + ", center: " + center);
});
But it results in this. Anyone have an idea how the calculation isn't done?
Position: 722, width: 83, center: NaN
Give position.left
$( "#main-nav li[class]" ).each(function( index ) {
var position = $(this).offset();
var width = $(this).width();
var center = parseInt(position.left) - (parseInt(width) / 2);
console.log("Position: " + position.left + ", width: " + width + ", center: " + center);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With