cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <body align="center">
  <div id="panel" align="center" class="animated fadeInDown warning" align="center">
    <div id="name">
      <input id="nameinput" value="Ім'я" onkeydown="if(event.keyCode == 13){document.getElementById('weightbefinput').focus()};" onfocus="select(this);" autofocus>
    </div>
    <br>
    <hr>
    <span>ПОЧАТКОВА ВАГА</span>
    <hr>
    <div id="weightbef">
      <input id="weightbefinput" value="125" onkeydown="if(event.keyCode == 13){document.getElementById('weightafterinput').focus()};" onfocus="select(this);">
    </div>
    <hr><span>ПОТОЧНА ВАГА</span>
    <hr>
    <div id="weightafter">
      <input id="weightafterinput" value="75" onkeydown="if(event.keyCode == 13){document.getElementById('submit').click()};" onfocus="select(this);">
    </div>
    <hr><span>РІЗНИЦЯ</span>
    <hr>
    <div id="weightminus"></div>
    <button id="submit" onclick="SubmitClick(this, event)">Ставайте на ваги</button>
  </div>
            
          
!
            
                body {
  		background: rgb(255, 255, 255);
  		text-align: center;
  		overfliw:hidden;
  }
  
  hr {
  		width: 80%;
  		box-shadow: 0 0 25px rgb(255, 255, 255);
  		background: rgb(45, 90, 26);
  		margin: 0px;
  }
  
  span {
  		font-size: 150%;
  }
  
  @media (min-width: 801px) {
  		#panel {
  				position: absolute;
  				left: calc(50% - 225px);
  				top: 16px;
  				width: 450px;
  				height: 475px;
  				box-shadow: 0 0 25px rgba(0, 0, 0, 0.5);
  				font-size: 100%;
  				font-family: 'Arial';
  				color: rgb(255, 255, 255);
  				background: rgb(51, 51, 51);
  				padding-top: 16px;
  		}
  }
  
  @media (max-width: 800px) {
  		#panel {
  				position: fixed;
  				top: 0;
  				left: 0px;
  				width: 100%;
  				height: 100%;
  				box-shadow: 0 0 25px rgba(0, 0, 0, 0.5);
  				font-size: 100%;
  				font-family: 'Arial';
  				color: rgb(255, 255, 255);
  				background: rgb(51, 51, 51);
  		}
  }
  
  #name {
  		margin-bottom: 10px;
  		margin-top: 10px;
  }
  
  #weightminus,
  #weightafter,
  #name,
  #weightbef {
  		font-size: 400%;
  		font-family: 'Arial';
  		color: rgb(255, 255, 255);
  }
  
  #weightminus {
  		display: none;
  }
  
  #weightbefinput,
  #weightafterinput,
  #nameinput {
  		text-align: center;
  		padding: 0px;
  		border: 0px solid transparent;
  		box-shadow: 0 0 5px rgb(150, 150, 150);
  		font-size: calc(100%);
  		background: rgba(51, 51, 51, 0);
  		color: #ffffff;
  		width: 80%;
  		border-radius: 0px;
  }
  
  #submit {
  		margin-top: 32px;
  		width: 80%;
  		height: 50px;
  		font-size: 200%;
  		background: #333333;
  		border: 1px solid white;
  		color: white;
  		cursor: pointer;
  }
            
          
!
            
              function rand(mi, ma) {
  return Math.floor(Math.random() * (ma - mi + 1) + mi);
}

function cUp(id, cnt, dur) {
  for (i = 0; i < cnt; i++) {
    setTimeout('document.getElementById("' + id + '").innerHTML=parseInt(document.getElementById("' + id + '").innerHTML)+1', i * dur);
  }
}

function cDn(id, cnt, dur) {
  for (i = 0; i < cnt; i++) {
    setTimeout('document.getElementById("' + id + '").innerHTML=parseInt(document.getElementById("' + id + '").innerHTML)-1', i * dur);
  }
}

id = 'weightafter';

function chval(a, tout) {
  if (a > 0) {
    cUp(id, a, tout);
  } else {
    cDn(id, -1 * a, tout);
  }
}

function getTout(a) {
  return Math.abs(1000 / a);
}

function counter(instructions) {
  var index = 0;
  var handle = window.setInterval(function() {
    if (index < instructions.length) {
      (function(a) {
        tout = getTout(a);
        chval(a, tout);
      })(instructions[index++]);
    } else {
      document.getElementById('weightminus').style.display = 'block';
      window.clearInterval(handle);
    }
  }, 2000);
}

function SubmitClick(el, ev) {
  el.style.display = "none";
  name = document.getElementById('nameinput').value;
  w0 = document.getElementById('weightbefinput').value;
  w1 = document.getElementById('weightafterinput').value;

  document.getElementById('name').innerHTML = name;
  document.getElementById('weightbef').innerHTML = w0;
  document.getElementById('weightafter').innerHTML = 0;

  wnow = w1 - w0;
  if (wnow > 0) {
    wnow = '+' + wnow
  }
  document.getElementById('weightminus').innerHTML = wnow;

  fin = parseInt(w1);
  val = fin + rand(-20, 20);
  vals = [val];

  c = rand(5, 9);
  for (i = 0; i < c; i++) {
    if (i < c - 5 && i > c + 5) {
      t = rand(-15, 15);
      val += t;
      vals.push(t);
    } else {
      if (val < fin) {
        t = rand(-5, 10);
        val += t;
        vals.push(t);
      } else {
        t = rand(-10, 5);
        val += t;
        vals.push(t);
      }
    }
  }
  vals.push(fin - val);
  counter(vals);
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console