简体   繁体   English

动态网格-显示嵌入式块

[英]dynamic grid - to display inline block

So far I've managed to code a few squares and each square has flip animation when I hover and when it is being clicked it will have a popup modal window. 到目前为止,我已经设法编码了几个正方形,并且当我将鼠标悬停在每个正方形上时,每个正方形都有翻转动画,当单击它时,将有一个弹出模式窗口。

I have 2 questions: 1) How do I display these squares so it will go across the page 10x10 (inline-block) Tried putting display inline block on the panel but didnt work 我有2个问题:1)我如何显示这些正方形,以便它能跨页面10x10(内嵌块)尝试将内嵌块显示在面板上但没有起作用

To have something like this: 拥有这样的东西:

在此处输入图片说明

2) In the future the number of grids will increase to say 30x10. 2)将来,网格数量将增加到30x10。 Is there a way I can draw these squares dynamically, JS function? 有没有一种方法可以动态绘制这些正方形,JS函数?

Any help/suggestions would be greatly appreciated 任何帮助/建议将不胜感激

1) Adding the inline-block to the .trigger class should have the effect you desire, for instance: 1)将inline-block添加到.trigger类应具有您想要的效果,例如:

.trigger {
    display: inline-block;
    width: 60px;
}

JS fiddle JS小提琴

2) You can do this straightforwardly with JQuery. 2)您可以使用JQuery直接执行此操作。 First you want a function to generate each box: 首先,您需要一个函数来生成每个框:

function genSquare(front, back) {
        return "<div class='trigger'>\
            <div class='hover panel'>\
          <div class='front'>\
            <div class='box1'>\
              <p>" + front + "</p>\
            </div>\
          </div>\
          <div class='back'>\
            <div class='box2'>\
              <p>"+back+"</p>\
            </div>\
          </div>\
        </div>\
  </div>"
}

Then you need to call this for every box you wish to add: 然后,您需要为每个要添加的框调用此命令:

$( document ).ready(function() {
    $(genSquare('hello', 'world')).appendTo( '.square-container' );
    ...
}

JQuery creates a new element based on the strings returned by genSquare() , and appends the element to objects with the class .square-container . jQuery根据genSquare()返回的字符串创建一个新元素,并将该元素追加到具有.square-container类的对象.square-container I'd actually recommend giving that container an ID to reference it by. 我实际上建议给该容器一个ID来引用它。

JS fiddle JS小提琴

Note that I've added the boxes dynamically before setting the trigger animation actions, so that the animations work on the dynamically added boxes. 请注意,在设置触发器动画动作之前,我已经动态添加了盒子,以便动画可以在动态添加的盒子上工作。 If you wish to add boxes dynamically some time after the page load, see https://stackoverflow.com/a/21239248/4799121 . 如果您希望在页面加载后的一段时间内动态添加框,请参见https://stackoverflow.com/a/21239248/4799121

you can add 'display: flex;' 您可以添加“ display:flex;” property to your .square-container. 属性添加到您的.square-container。

.square-container {
   width: 60px;
   margin: 35px auto;
   display: flex;
   margin-left: 10px;
   padding-left: 10px;
}

And then add padding-left to the .panel. 然后将padding-left添加到.panel。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM