簡體   English   中英

Html5 有一個動畫畫布作為 Div 元素的背景嗎?

[英]Html5 Have an Animated Canvas as the background of a Div Element?

我想要這個 JS - https://codepen.io/jkiss/pen/OVEeqK - 作為我首頁上 div 元素的背景。

html

<script src="{% static 'home/animated.js' %}"></script>
        <div class = "content-section">
            <div id = "canvas-wrap">
                <canvas id="nokey"></canvas>
                <div class = "bg-1 media" id = "overlay">
                    <div class = "container">
                        <img src = "../../../media/pfp.jpg"  class = "profile-img img-thumbnail rounded-circle">
                        <div class = "media-body intro">
                            <h1 class = "">My Name</h1>
                            <h4>Aspiring Web Developer</h4>
                        </div>
                    </div>
                </div>
            </div>

CSS

body{
    background-color: #222222;
    font:inherit;
    font-family: Titillium;
    margin:0;
    padding:0;
}

#canvas-wrap { position:absolute; width:100px; height:50px; z-index:0 }
#canvas-wrap canvas { position: absolute; top:0; left:0; z-index:0 }

#nokey{
    background-color: darkblue;
}

.content-section{
    margin-left: 50px;
    margin-right: 50px;
    margin-bottom: 50px;
    background: aliceblue;
}

.bg-1 .container{
    display: flex;
    align-items: center;
    justify-content: center;
}

.intro{
    flex: none;
    margin-top: 200px;
    margin-bottom: 200px;
    padding-left: 25px;
    color: white;
}

我能做什么? 目前,畫布占據了整個屏幕,並在其后面創建了 div。

使用z-index CSS 屬性將 div 移動到更高的其他元素:

 #nokey{ background-color: darkblue; z-index: 1; // or more, if other elements has one }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM