jQuery:在不需要的时候将div叠加在一起

时间:2023-01-31 15:03:18

Currently, I am working on a project to generate a dynamic card page. This page is based on the input of a specific json feed (e.g. a user role).

目前,我正在开发一个生成动态卡片页面的项目。此页面基于特定json订阅源(例如用户角色)的输入。

profile.json

    {
      "Messages": "card1",
      "Activities": "card2",
      "Agenda": "card3",
      "Users": "card4",
      "Charts": "card5"
    }

Next, I use jQuery and Kendo UI to create cards. First, I need to extract the information from the json feed. As you may notice, every card will be placed inside a div. And every div will be appended to the cards div:

接下来,我使用jQuery和Kendo UI来创建卡片。首先,我需要从json提要中提取信息。正如您可能注意到的那样,每张卡都将被放置在div中。并且每个div都将附加到卡片div:

Below is code of index.html

下面是index.html的代码

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../../style/font-awesome.css">
    <link rel="stylesheet" href="/style/cards.css" />
    <script src="../lib/jquery.min.js"></script>
    <script src="../lib/custom/effects.min.js"></script>

</head>
<body>
    <div id="cards"></div>

    <script>
        $.getJSON("profile.json", function (data) {
            $.each(data, function (key, val) {
                var card = "<div id='" + val + "' height='180' width='175'></div>";
                $("#cards").append(card);
                $('#' + val).load(val + '/index.html');
            });
        });
    </script>

</body>
</html>

Every card does have some simple styling:

每张卡都有一些简单的造型:

One of the card (card7/index.html)
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>

    <style>
        html {
            overflow: hidden;
        }

        a {
            color: #428bca;
            text-decoration: none;
        }

        #card7 {
            width: 150px;
            height: 150px;
            position: relative;
        }

        .front {
            padding: 10px;
            text-align: center;
            position: absolute;
            width: 140px;
            height: 140px;
            box-shadow: 0 2px 4px 0 rgba(0,0,0,0.2);
            transition: 0.3s;
            border-radius: 1px;
            background-color: #f5f4f5;
        }

        .back {
            font-size: smaller;
            padding: 10px;
            text-align: left;
            position: absolute;
            width: 140px;
            height: 140px;
            box-shadow: 0 2px 4px 0 rgba(0,0,0,0.2);
            transition: 0.3s;
            border-radius: 1px;
            background-color: #f5f4f5;
        }

        .front:hover, .back:hover {
            box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
            transition: 0.3s;
            border-radius: 5px;
        }

        img {
            border-radius: 5px 5px 0 0;
        }

        .badge:after {
            content: "1";
            position: absolute;
            background: rgba(255, 0, 0, 0.85);
            height: 2rem;
            top: 1rem;
            right: 2rem;
            width: 2rem;
            text-align: center;
            line-height: 2rem;
            font-size: 1rem;
            border-radius: 50%;
            color: white;
        }

        .seeBack {
            margin-top: -30px;
            margin-right: -10px;
            float: right;
            border-style: solid;
            border-width: 0 0 40px 40px;
            border-color: transparent;
        }

        .seeBack:hover {
            border-color: transparent transparent #428bca transparent;
            transition: 0.5s;
        }

        .seeFront {
            margin-top: 10px;
            margin-left: -10px;
            float: left;
            border-style: solid;
            border-width: 40px 0 0 40px;
            border-color: transparent;

        }

        .seeFront:hover {
            border-color: transparent transparent transparent #428bca;
        }
    </style>

</head>
<body>

    <div id="card7">
        <div class="front">
            <i class="fa fa-undo fa-5x"></i>
            <h4><b>Tijdlijn</b></h4>
            <div class="seeBack"></div>
        </div>
        <div class="back">
            <p><a href="#">Situatie vorige week</a></p>
            <p><a href="#">Situatie vorige maand</a></p>
            <p><a href="#">Situatie vorig jaar</a></p>
            <div class="seeFront"></div>
        </div>
    </div>

    <script>
        $(document).ready(function () {
            kendo.fx($("#card7")).flip("horizontal", $(".back"), $(".front")).play();
            var card = kendo.fx($("#card7")),
                flip = card.flip("horizontal", $(".front"), $(".back"));

            flip.duration(100);

            $(".seeBack").click(function () {
                flip.stop().play();
            });

            $(".seeFront").click(function () {
                flip.stop().reverse();
            });

        });

    </script>
</body>
</html>

As you may expect, the program itself does not work properly. All cards will be displayed on top of each other in index.html, although they are placed in various div. I don't know what the problem is and I cannot fix this. Hopefully one can help me.

正如您所料,程序本身无法正常工作。所有卡片都将在index.html中显示在彼此之上,尽管它们被放置在各种div中。我不知道问题是什么,我无法解决这个问题。希望有人可以帮助我。

jQuery:在不需要的时候将div叠加在一起

All cards are placed on top of each other.

所有卡片都放在一起。

1 个解决方案

#1


1  

Use static or relative position for .front and .back divs

对.front和.back div使用静态或相对位置

Read that article about positioning for more info http://www.w3schools.com/cssref/pr_class_position.asp

阅读有关定位的文章以获取更多信息http://www.w3schools.com/cssref/pr_class_position.asp

#1


1  

Use static or relative position for .front and .back divs

对.front和.back div使用静态或相对位置

Read that article about positioning for more info http://www.w3schools.com/cssref/pr_class_position.asp

阅读有关定位的文章以获取更多信息http://www.w3schools.com/cssref/pr_class_position.asp