์ฐฝ ํฌ๊ธฐ์ ๊ด๊ณ์์ด ๊ณ ์ ๋ ์
๋๋น์ ๋์ด๋ฅผ ๋ง๋ค๋ ค๊ณ ํฉ๋๋ค. ๊ฐ ์์ ฏ์ด 20px ๋จ์๋ก ์ ๋์ ์ผ๋ก ์์๋๋ก ์ด๋ํ ์์๋ 20px x 20px ๊ทธ๋ฆฌ๋๋ฅผ ๋ง๋ค๊ณ ์ถ์ต๋๋ค. cellHeight: 20
์ ๋ฌํ์ฌ ๋์ด๋ฅผ ๊ณ ์ ํ ์ ์์ง๋ง ๋๋น๊ฐ ์ ์๋ํ์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ด๊ฒ์ด ๋ด๊ฐ ์ต์
์ผ๋ก ์ ๋ฌํ๋ ๊ฒ์
๋๋ค.
var options = {
float: true,
width: 53,
acceptWidgets: '.grid-stack-item',
cellHeight: 20,
verticalMargin: 0,
disableResize: true,
alwaysShowResizeHandle: false
};
$('#grid-1').gridstack(options);
cellWidth: 20
์๋ํ์ง๋ง ์๋ํ์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ํ % ๋์ px๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ณ์ฐ๋๋๋ก scss ์คํฌ๋ฆฝํธ๋ฅผ ์์ ํ์ต๋๋ค.
.grid-stack > .grid-stack-item {
$gridstack-columns: 60;
<strong i="11">@for</strong> $i from 1 through $gridstack-columns {
&[data-gs-width='#{$i}'] { width: $i * 20px; }
&[data-gs-x='#{$i}'] { left: $i * 20px; }
}
}
์ด๋ ๊ฒํ๋ฉด ๊ทธ๋ฆฌ๋ ํญ๋ชฉ์ด ์ฌ๋ฐ๋ฅธ 20px ๊ทธ๋ฆฌ๋ ์์น์ ์ค๋
๋์ง๋ง ์ํ ๋๋๊ทธ๋ ๋ ๋ถ๋๋ฝ์ต๋๋ค. ์ํ ๋๋๊ทธ๊ฐ ๊ทธ๋ฆฌ๋ ๋๋น์ ๋งคํ๋๋๋ก .scss ์คํฌ๋ฆฝํธ์ ์ถ๊ฐํด์ผ ํ ๋ค๋ฅธ ๊ฒ์ด ์์ต๋๊น? ์๋๋ฉด width
๋๋ cellWidth
๋งค๊ฐ ๋ณ์์ ๋ํด ๋ค๋ฅธ ์์
์ ์ํํด์ผํฉ๋๊น? % ๊ณ์ฐ์์ ๋ฒ์ด๋๊ณ ์ถ์ต๋๋ค. :)
@cblokker ์ด ์์ ์ ์ํํ๋ ๋ฐฉ๋ฒ์ ์์
์ด๊ฒ์ ๋์๊ฒ ์ฌํ์ ์ผ์ผํค๋ ๊ธฐ๋ฅ์ ๋๋ค.
GridStack.prototype.cellWidth = function() {
return Math.round(this.container.outerWidth() / this.opts.width);
};
ํฝ์ ๊ธฐ๋ฐ ๋๋น์ ๊ฒฝ์ฐ ์ด์ ํฝ์ ๋จ์๋ก ์ ์ํ๋ CSS์ ํจ๊ป this.opts.width ๋ง ๋ฐํํ๋ ค๋ฉด์ด ํจ์๊ฐ ํ์ํฉ๋๋ค.
์ด๋ค ๋ชจ๋ธ์ ์์๋์ง (% ๋๋ px) ๊ฒฐ์ ํ๊ธฐ ์ํด gridstack์ ์ค๋งํธ ๊ธฐ๋ฅ์ด ํ์ํ๊ฑฐ๋ ์ด๋ค ๋ชจ๋์ธ์ง ์๋ ค์ฃผ๋ ๊ตฌ์ฑ ์ต์ ์ด ์์ด์ผํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
ํธ์ง : ๊ทธ๋ ๊ฒ ๊ฐ๋จํ์ง ์์ ์๋ ์์ต๋๋ค. ๋๋ ์ง๊ธ ๊ทธ๊ฒ์๋ณด๊ณ ๋๊ณ ์๋ค.
ํธ์ง 2 : ๋ด 5 ๋ถ ์์ . ์ ์ด๋ ์์ง ๋ฐ์ ํ ํ๋ฆ์ด ์์ง ์์ต๋๋ค.
Diff : ์ง์ ํฝ์
๋๋น
4k ํ๋ฉด์์ ๊ทธ๋ฆฌ๋๋ฅผ ๋ณด๋ ๋ฐ ๋ฌธ์ ๊ฐ ์๊ธฐ ๋๋ฌธ์ ๋๋๋ก ์น ํ์ด์ง๋ฅผ ๋๊ฒ ๋ง๋ค๊ณ ์ถ์ ๋ ํฌ๊ธฐ๊ฐ ๊ฑฐ์ ์ ๋ฐ ์ธ ์ ๊ทธ๋ฆฌ๋๋ฅผ ์ค์ ํ ๋ค์ ํฌ๊ธฐ๋ฅผ ์กฐ์ ํ ๋ ๋ค๋ฅธ ์ฌ๋๋ค์ด ์ฌ์ฉํ ํด์๋๋ก ํ์ด์ง๋ฅผ ๋ด๋ ค ๊ฐ๋ฉด ๋๋น๊ฐ ๋๋ฌด ์ข์ต๋๋ค.
์ ๋์ด ๊ธฐ๋ฅ์ด gridstack์์ ์ง์๋๋ ๊ฒ์๋ณด๊ณ ์ถ์ต๋๋ค.
์ฌ๊ธฐ์์๋ ๋ง์ฐฌ๊ฐ์ง์ ๋๋ค. ๊ทธ๋ฆฌ๋ ์คํ์์๋ณด๊ณ ์ถ์ต๋๋ค.
๊ทธ ๋์ ๊ฐ๋จํ ์ฌ์ฉ ์ฌ๋ก (1 ํ, disabledOneColumnMode, height = 1)๋ฅผ ์ํด ํดํน ํ ์์์์ต๋๋ค.
๋ชจ๋ ํ์ผ์ 100px ๋๋น๋ก ๊ฐ์ ํ๋ ค๋ฉด (๋ด ๋ชจ๋ ํ์ผ์ ๋๋น = 1์ด๋ฉฐ ๋๋น์ ๋ํด ์ด๋ ต์ง ์์์ผ ํจ) :
CSS์์
$tile-width: 100px; /*100px*/
.grid-stack-item[data-gs-width="1"] { width: $tile-width; min-width: $tile-width; max-width: $tile-width; }
.grid-stack-item {
<strong i="9">@for</strong> $i from 1 through 20 {
&[data-gs-x='#{$i}'] { left: $i * $tile-width; }
}
}
๊ฑด์ค์:
const width = $('.grid-stack').outerWidth();
this.grid = $('.grid-stack').gridstack({
auto: false,
cellHeight: 80,
disableResize: true,
verticalMargin: 0,
width: Math.round(width/100),
height: 1,
disableOneColumnMode: true
}).data('gridstack');
ํฌ๊ธฐ ์กฐ์ ํธ๋ค๋ฌ์์ ๋๋น ์ฌ์ค์
resizeHandler() {
const width = $('.grid-stack').outerWidth();
const grid = $('.grid-stack').data('gridstack');
grid.setGridWidth(Math.round(width/100), true);
}
ํดํน์ ํ์ฌ ๊ทธ๋ฆฌ๋ ๋๋น (px)๋ฅผ ๊ธฐ์ค์ผ๋ก ๋๋น (์ด ์)๋ฅผ ์กฐ์ ํ์ฌ cellWidth๋ฅผ 100px (CSS์ ์ค์ ๋๋๋ก)๋ก ๊ฐ์ ํ๋ ๊ฒ์
๋๋ค.
cellHeight
๋ฅผ ์ํ๋๋๋ก ์ค์ ํ ์ ์์ผ๋ฉฐ ์ปจํ
์ด๋๋ฅผ ๋ง๋ค๊ณ ์ต์
์ gridstack์ ์ ๋ฌํ๊ธฐ ์ ์ Javascript๋ฅผ ์ฌ์ฉํ์ฌ ์ฐจ์์ ๊ฒฐ์ ํ ์ ์์ต๋๋ค. ์ด๋ฌํ ๋ฐฉ์์ผ๋ก ์ํ๋ ๋น์จ์ ์ค์ ํ๊ณ ํน์ ํฝ์
๊ธฐ๋ฐ ๋๋น์ ๋์ด๋ฅผ ์ค์ ํ ์๋ ์์ต๋๋ค.