0

我正在尝试获取变量的值并将其用于元素的宽度,但我想从中删除小数并使其成为整数。我到了这里,但似乎无法让它工作

var grid_width= width:($(window).width() / 270)

$("#grid").css({
    width: grid_width.toFixed(0)
});

JS:

<script>

$('#grid').isotope({
  // options
  itemSelector : '.iso',
  masonry: {
    columnWidth: 270
  },
  animationEngine : 'jquery'
});



var grid_width = $(window).width() / 270;

$("#grid").css({
    width: Math.floor( grid_width ) + 'px',
    background: "green"
});

</script>
4

2 回答 2

0

尝试这个

var grid_width = $(window).width() / 270;

$("#grid").css({
    width: Math.floor( grid_width ) + 'px'
});
于 2012-12-13T19:26:48.290 回答
0

将数字解析为对应的整数:

$("#grid").css({
    width: parseInt(grid_width)
});
于 2012-12-13T19:40:18.850 回答