Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function soundwaveInit() {
  2.  
  3.     var wrap = document.getElementById('soundwave');
  4.  
  5.     var windowWidth = (window.innerWidth > 1920 ? 1920 : window.innerWidth);
  6.     var barWidth = 1;
  7.     var barSpaceBetween = 2;
  8.     var barCount = Math.round(windowWidth / (barWidth + barSpaceBetween));
  9.     var nodeBar;
  10.  
  11.     wrap.style.width = windowWidth + 'px';
  12.     wrap.style.left = '50%';
  13.     wrap.style.marginLeft = -(windowWidth / 2) + 'px';
  14.  
  15.     for (var i = 0; i < barCount; i++) {
  16.  
  17.         if ( barCount > parseInt(windowWidth) / 2 ) {
  18.             var animationDur = Math.floor((Math.random() * 10) + i / 1000) + 's';
  19.             var animationDel = '0.' + Math.floor((Math.random() * 5) + i) + 's';
  20.         } else {
  21.             var animationDur = Math.floor((Math.random() * 5)) + 's';
  22.             var animationDel = '0.' + Math.floor((Math.random() * 10)) + 's';
  23.         }
  24.  
  25.         nodeBar = document.createElement("div");
  26.         nodeBar.classList.add('bar');
  27.         wrap.append(nodeBar);
  28.         nodeBar.style.animationDuration = animationDur;
  29.         nodeBar.style.animationDelay = animationDel;
  30.  
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement