简体   繁体   English

建议在容器div中随机显示元素

[英]Suggestion for displaying elements randomly within a container div

Looking for a demo that randomly position elements within a container div and fade them out/in at random times. 寻找一个演示,该演示将元素随机放置在容器div中并在随机时间淡入/淡出。 Any suggestions? 有什么建议么? Maybe there is a premade library that has the function built in? 也许有一个内置函数的预制库? Thanks a ton. 万分感谢。

 function generateRandomNode(container) { var node = document.createElement('SPAN'); node.style.top = Math.random() * 100 + '%'; node.style.left = Math.random() * 100 + '%'; container.appendChild(node); setTimeout(function(){node.remove();},1000); } setInterval(function() { generateRandomNode(document.getElementById('container')); },1); 
 #container { width:500px; height:500px; } .random-element { position: relative; } .random-element>* { width:3px; height: 3px; opacity:0; border-radius: 50%; position:absolute; background-color: #000; animation: fade 500ms ease; } @keyframes fade { 0% {opacity:0} 50%{opacity:1} 100%{opacity:0} } 
 <div class="random-element" id="container"></div> 

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

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