gpt4 book ai didi

javascript - 使用 100vh 定位 div

转载 作者:行者123 更新时间:2023-11-28 03:49:46 27 4
gpt4 key购买 nike

在这段代码中,我保存了两个 div 元素,每个元素都设置在页面的整个长度 (100vh) 上,但不是一个在另一个之上,就好像我想重叠一样。部分问题得到解决,而不是在 keywords-js 中使用“绝对”,我将“静态”放在“静态”中,然后它们不会彼此重叠,但将动画粒子强加在带有 Content 的 div 上

HTML

<div id="particles-js">
</div>

<div class="content">
<h1>Content</h1>
</div>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/particles.js/2.0.0/particles.min.js"></script>

CSS

#particles-js {
position: absolute;
width: 100%;
height: 100vh;
z-index: -1;
background-color: #222;
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
}


canvas{
position: absolute;
width: 100%;
height: 500px;
z-index: -1;
}

.content
{
position: relative;
height: 100vh;
background-color: #F4F7F5;
color: #222222;
}

和JS

particlesJS("particles-js", 
{
"particles": {
"number": {
"value": 50,
"density": {
"enable": true,
"value_area": 800
}
},
"color": {
"value": "#ffffff"
},
"shape": {
"type": "circle",
"stroke": {
"width": 0,
"color": "#000000"
},
"polygon": {
"nb_sides": 5
},
"image": {
"src": "img/github.svg",
"width": 100,
"height": 100
}
},
"opacity": {
"value": 0.5,
"random": false,
"anim": {
"enable": false,
"speed": 1,
"opacity_min": 0.1,
"sync": false
}
},
"size": {
"value": 3,
"random": true,
"anim": {
"enable": false,
"speed": 40,
"size_min": 0.1,
"sync": false
}
},
"line_linked": {
"enable": true,
"distance": 150,
"color": "#ffffff",
"opacity": 0.4,
"width": 1
},
"move": {
"enable": true,
"speed": 3,
"direction": "none",
"random": false,
"straight": false,
"out_mode": "out",
"bounce": false,
"attract": {
"enable": false,
"rotateX": 600,
"rotateY": 1200
}
}
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": {
"enable": false,
"mode": "repulse"
},
"onclick": {
"enable": false,
"mode": "push"
},
"resize": true
},
"modes": {
"grab": {
"distance": 527.4388051113614,
"line_linked": {
"opacity": 1
}
},
"bubble": {
"distance": 599.3622785356379,
"size": 63.93197637713472,
"duration": 5.354303021585032,
"opacity": 0.30367688779138985,
"speed": 3
},
"repulse": {
"distance": 271.7108996028225,
"duration": 0.4
},
"push": {
"particles_nb": 4
},
"remove": {
"particles_nb": 2
}
}
},
"retina_detect": true
});

最佳答案

这是你想要的吗?

particlesJS("particles-js", {
"particles": {
"number": {
"value": 50,
"density": {
"enable": true,
"value_area": 800
}
},
"color": {
"value": "#ffffff"
},
"shape": {
"type": "circle",
"stroke": {
"width": 0,
"color": "#000000"
},
"polygon": {
"nb_sides": 5
},
"image": {
"src": "img/github.svg",
"width": 100,
"height": 100
}
},
"opacity": {
"value": 0.5,
"random": false,
"anim": {
"enable": false,
"speed": 1,
"opacity_min": 0.1,
"sync": false
}
},
"size": {
"value": 3,
"random": true,
"anim": {
"enable": false,
"speed": 40,
"size_min": 0.1,
"sync": false
}
},
"line_linked": {
"enable": true,
"distance": 150,
"color": "#ffffff",
"opacity": 0.4,
"width": 1
},
"move": {
"enable": true,
"speed": 3,
"direction": "none",
"random": false,
"straight": false,
"out_mode": "out",
"bounce": false,
"attract": {
"enable": false,
"rotateX": 600,
"rotateY": 1200
}
}
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": {
"enable": false,
"mode": "repulse"
},
"onclick": {
"enable": false,
"mode": "push"
},
"resize": true
},
"modes": {
"grab": {
"distance": 527.4388051113614,
"line_linked": {
"opacity": 1
}
},
"bubble": {
"distance": 599.3622785356379,
"size": 63.93197637713472,
"duration": 5.354303021585032,
"opacity": 0.30367688779138985,
"speed": 3
},
"repulse": {
"distance": 271.7108996028225,
"duration": 0.4
},
"push": {
"particles_nb": 4
},
"remove": {
"particles_nb": 2
}
}
},
"retina_detect": true
});
body {
margin:0;
}
#particles-js {
position:relative;
width: 100%;
height: 100vh;
background-color: #222;
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
}

canvas {
position: absolute;
width: 100%;
height: 100%;
}

.content {

background:#000;
height: 100vh;
color: #fff;
}
.content h1 {
margin-top:0;
}
<div id="particles-js">
</div>

<div class="content">
<h1>Content</h1>
</div>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/particles.js/2.0.0/particles.min.js"></script>

关于javascript - 使用 100vh 定位 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48104292/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com