【问题标题】:How to add grid for angular-gridster?如何为 angular-gridster 添加网格?
【发布时间】:2018-12-07 06:47:20
【问题描述】:

如何为angular-gridster添加动态坐标网格?

我的例子http://jsfiddle.net/qqzvjvfx/24/

<div ng-app="someApp" ng-controller="someCtrl">
    <div gridster="gridsterOpts">
        <ul>
            <li class="" gridster-item="block" ng-repeat="block in sorted_blocks">
                <div class="panel panel-default">
                    <div class="panel-heading">{{ block.title }}</div>
                    <div class="panel-content image-responsive" 
                         ng-style="{'background-image':'url(' + block.image + ')'}"></div>
                </div>
            </li>
        </ul>
    </div>
</div>

角度控制器:

angular.module('someApp', ['gridster']).controller('someCtrl', function ($scope, $http) {
    $scope.gridsterOpts = 
    {
        resizable: {
            enabled: true
        },
        columns: 4,
        rows: 16,
        minRows: 4,
        margins: [0,0],
        floating: false
    };
    $scope.sorted_blocks = [{
        id: 1,
        sizeX: 1,
        sizeY: 1,
        image: 'http://i.imgur.com/NI1Xm16.jpg',
        title: 'title1',
        row: 1,
        col: 2
    }, {
        id: 2,
        sizeX: 2,
        sizeY: 1,
        image: 'http://i.imgur.com/x6qmeUY.jpg',
        title: 'title2',
        row: 0,
        col: 0
    }];
});

CSS:

.panel {
    display: flex;
    flex-flow: column wrap;
    height: 100%;
}

.panel .panel-content {
    flex-grow: 1;
}

.image-responsive {
    background-size: contain;
    background-repeat: no-repeat;
}

gridster 字段的宽度是固定的 - 4 列,高度是动态的,从 4 到 16 行。 我需要在块下添加网格,例如this

【问题讨论】:

    标签: javascript css angularjs


    【解决方案1】:

    我找到了这个 codepen by Jason Delia,将其插入您的 gridster 作品中。

    当然,您必须更改背景颜色,但它应该可以满足您的需要:

    html {
      height: 100%;
    }
    
    body {
      margin: 0;
      padding: 0;
      height: 100%;
      background-color: #434343;
      background-image: linear-gradient(#434343, #282828);
    }
    
    #content {
      background-color: transparent;
      background-image: linear-gradient(0deg,  transparent 24%, rgba(255, 255, 255, .05) 25%, rgba(255, 255, 255, .05) 26%, transparent 27%, transparent 74%, rgba(255, 255, 255, .05) 75%, rgba(255, 255, 255, .05) 76%, transparent 77%, transparent), 
                        linear-gradient(90deg, transparent 24%, rgba(255, 255, 255, .05) 25%, rgba(255, 255, 255, .05) 26%, transparent 27%, transparent 74%, rgba(255, 255, 255, .05) 75%, rgba(255, 255, 255, .05) 76%, transparent 77%, transparent);
      height: 100%;
      background-size: 50px 50px;
    }
    &lt;div id="content"&gt;&lt;/div&gt;
    猜你喜欢
    • 2016-05-11
    • 1970-01-01
    • 1970-01-01
    • 2022-12-02
    • 1970-01-01
    • 2015-05-05
    • 2015-12-28
    • 2020-07-19
    • 1970-01-01
    相关资源
    最近更新 更多