我試圖將我的頁面帖子設置爲卡片到id =「content」的一個div(如G +上)。jQuery - 設置計算的div寬度
#content {
margin-top: 120px;
margin-bottom: 70px;
margin-left: auto ;
margin-right: auto ;
height: auto;
}
.card {
height: 250px;
width: 500px;
margin: 10px;
float: left;
}
我想計算一下我可以在屏幕上放入多少.card
。 所以,我想這一點:
$(document).ready(function() {
"use strict";
var cardAmount = (Math.floor($(window).width/520))*520;
$("#content").css("width", cardAmount);
});
但問題是,(我認爲).css
必備的第二個參數的字符串,它不是。
您忘記'.width'後的括號。將其更改爲'.width()':[** working result **](http://jsfiddle.net/nquhwh7z/1/) – myfunkyside 2014-10-11 18:24:38