我正在尝试获取变量的值并将其用于元素的宽度,但我想从中删除小数,并将其作为整数。我到了这里,但似乎无法使它工作
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>
答案 0 :(得分:0)
试试这个
var grid_width = $(window).width() / 270;
$("#grid").css({
width: Math.floor( grid_width ) + 'px'
});
答案 1 :(得分:0)
将数字解析为相应的整数:
$("#grid").css({
width: parseInt(grid_width)
});