【问题标题】:Grid Element initialising vertically Gridster.js网格元素垂直初始化 Gridster.js
【发布时间】:2015-06-13 03:45:27
【问题描述】:

好吧,我使用 Gridster.js 来制作类似仪表板的环境,因此编写了以下代码。问题是,实际上我希望根据它们的 html 标签属性“data-row”和“data-col”中指定的行号和列号来初始化所有元素垂直堆叠。

我检查了控制台没有 Js 错误。页面加载完毕,元素垂直堆叠后,我仍然可以拖动它们,然后可以通过一个接一个的拖动将它们形成一个网格。

请谁能告诉我在页面加载时没有让元素以类似网格的格式正确堆叠是我做错了什么。

这是输出的图像:

代码如下:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Gridster Test page</title>
</head>
<body>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <link href="../Third Party Libraries/Gridster/Gridster.min.css"></link>
    <script src="../Third Party Libraries/Gridster/Gridster.min.js"></script>
    <script>
            var gridster;
            $(function () {
                gridster = $(".gridster > ul").gridster({

                    widget_margins: [10, 10],
                    widget_base_dimensions: [140, 140],
                    min_cols: 6,
                    min_rows: 5,
                    resize: {
                        enabled: true
                    }
                }).data('gridster');
            })
</script>
<style>
    ul, ol {
        list-style: none;
    }

    h1 {
        margin-bottom: 12px;
        text-align: center;
        font-size: 30px;
        font-weight: 400;
    }

    h3 {
        font-size: 25px;
        font-weight: 600;
        color: white;
    }

    /* Gridster styles */
    .demo {
        margin: 3em 0;
        padding: 7.5em 0 5.5em;
        background: #004756;
    }

        .demo:hover .gridster {
            opacity: 1;
        }

    .gridster {
        width: 940px;
        margin: 0 auto;
        opacity: .8;
        -webkit-transition: opacity .6s;
        -moz-transition: opacity .6s;
        -o-transition: opacity .6s;
        -ms-transition: opacity .6s;
        transition: opacity .6s;
    }

        .gridster .gs_b {
            background: blue;
            cursor: pointer;
            -webkit-box-shadow: 0 0 5px rgba(0,0,0,0.3);
            box-shadow: 0 0 5px rgba(0,0,0,0.3);
        }
        .gridster .gs_y {
            background: yellow;
            cursor: pointer;
            -webkit-box-shadow: 0 0 5px rgba(0,0,0,0.3);
            box-shadow: 0 0 5px rgba(0,0,0,0.3);
        }
        .gridster .gs_g {
            background: green;
            cursor: pointer;
            -webkit-box-shadow: 0 0 5px rgba(0,0,0,0.3);
            box-shadow: 0 0 5px rgba(0,0,0,0.3);
        }
        .gridster .gs_o {
            background: orange;
            cursor: pointer;
            -webkit-box-shadow: 0 0 5px rgba(0,0,0,0.3);
            box-shadow: 0 0 5px rgba(0,0,0,0.3);
        }
</style>
<div class="gridster ready">
    <ul style="height: 640px; width: 960px; position: relative;">
        <li data-row="1" data-col="1" data-sizex="1" data-sizey="1" class="gs_b">a</li>
        <li data-row="2" data-col="1" data-sizex="1" data-sizey="1" class="gs_b">b</li>
        <li data-row="3" data-col="1" data-sizex="1" data-sizey="1" class="gs_b">b</li>

        <li data-row="1" data-col="2" data-sizex="2" data-sizey="1" class="gs_g">c</li>
        <li data-row="2" data-col="2" data-sizex="2" data-sizey="2" class="gs_g">d</li>

        <li data-row="1" data-col="4" data-sizex="1" data-sizey="1" class="gs_y">e</li>
        <li data-row="2" data-col="4" data-sizex="2" data-sizey="1" class="gs_y">f</li>
        <li data-row="3" data-col="4" data-sizex="1" data-sizey="1" class="gs_y">g</li>

        <li data-row="1" data-col="5" data-sizex="1" data-sizey="1" class="gs_o">h</li>
        <li data-row="3" data-col="5" data-sizex="1" data-sizey="1" class="gs_o">i</li>

        <li data-row="1" data-col="6" data-sizex="1" data-sizey="1" class="gs_g">k</li>
        <li data-row="2" data-col="6" data-sizex="1" data-sizey="2" class="gs_b">j</li>
    </ul>
</div>

【问题讨论】:

    标签: javascript html css gridster


    【解决方案1】:

    尝试从类中删除“就绪”部分

    <div class="gridster">
    

    我很确定插件已经完成了。

    【讨论】:

      猜你喜欢
      • 2014-07-28
      • 1970-01-01
      • 1970-01-01
      • 2018-06-11
      • 2016-04-12
      • 1970-01-01
      • 2019-06-13
      • 2018-07-22
      • 1970-01-01
      相关资源
      最近更新 更多