我有一个javascript计算的小问题.我有这样的功能:
$( "#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);
});
Run Code Online (Sandbox Code Playgroud)
但它导致了这一点.任何人都知道如何进行计算?
Position: 722, width: 83, center: NaN
Run Code Online (Sandbox Code Playgroud)
给 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);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
58 次 |
| 最近记录: |