javascript 条形音箱上去

标签 javascript css

我找到了 this pen在代码笔上。我想使用它,但是条形图向下而不是向上 我怎样才能让它向上?

var elem = $('div');
var count = elem.length;

var loop = function() {

  setTimeout(function() {
    elem.each(function() {
      var $this = $(this);
      var height = (Math.random() * 20) + 1;
      $this.css({
        'background': 'rgba(255, 255, 255,1)',
        'top': height,
        'height': height
      });
    });
    loop();
  }, 320);

}

loop();
section {
  width: 100%;
  display: inline-block;
  margin: auto;
  background: #222;
}

div {
  background: #fff;
  float: left;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  vertical-align: middle;
  height: 1px;
  transition: all linear 250ms;
  width: 2px;
  margin-left: 1px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<section>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</section>

最佳答案

var elem = $('.sound-bars div');
var count = elem.length;

var loop = function(){ 
  
  setTimeout(function(){
    elem.each(function(){
      var $this = $(this);
      var height = (Math.random() * 20) + 1;
      $this.css({
        'height': height
      });
    });
    loop();
  }, 320);
  
}
    
loop();
.sound-bars {
  width: 100%;
  display: flex;
  background: #222;
  position: absolute;
  bottom: 0;
  align-items: baseline;
}
.container {
  height: 80px;
  position: relative
}
.sound-bars div {
	background: #fff;
  height: 1px;  
  transition: all linear 250ms;
  width: 2px; 
  margin-left:1px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
  <div class="sound-bars">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </div>
</div>

关于javascript 条形音箱上去,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43089535/

相关文章:

javascript - 将 @author 的使用视为代码风格违规

javascript - Nodejs 可怕的异步问题

Jquery slider 在事件时显示 div 文本

css - 与IE10+相比,IE9不支持的所有CSS规则有没有聪明的方法?

html - 出现透明物体

html - 页面底部 1px 行,但仅限移动设备

css - 线性渐变未显示全色标

javascript - 当 autoProcessQueue 设置为 false 时,Dropzone.js 只上传两个文件

javascript - 谷歌地图 isLocationOnEdge() 方法不适用于数据层功能

javascript - 无法使用 ascii 46 `.`(句点)聚焦下一个输入字段