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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <div class="demo_wrapper">
  <i>Oh look at the time!</i>
  <div class="counter">
    <div class="digitRoll"></div>
    <div class="digitRoll"></div>
    <div class="staticRoll">
      <div><i>:</i></div>
    </div>
    <div class="digitRoll"></div>
    <div class="digitRoll"></div>
    <div class="staticRoll">
      <div><i>:</i></div>
    </div>
    <div class="digitRoll"></div>
    <div class="digitRoll"></div>
  </div>

  <i>But what year is it<br><i>(Click or scroll the barrels to interact)</i></i>
  <div class="counter">
    <div class="digitRoll"></div>
    <div class="digitRoll"></div>
    <div class="digitRoll"></div>
    <div class="digitRoll"></div>
  </div>
  <i><i>Auto guess</i><input type="checkbox" id="guess"></input></i>
</div>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Megrim|Press+Start+2P');

html,body,.demo_wrapper
{
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none; 
  user-select: none;
  background: #72baac;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.demo_wrapper, .counter
{
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.demo_wrapper i
{
  font-size: 4vh;
  width: 100%;
  text-align: center;
  color: #f8f8f8;;
}

.demo_wrapper i i
{
  font-size: 2.75vh;
  opacity: 0.5;
}

.counter
{
  
  width: 140vh;
  height: 14vh;
  overflow: hidden;
  /*background: #ee7546;*/
}


.digitRoll::before, .staticRoll::before
{
  content: ' ';
  display: block;
  margin-top: 10%;
  height: 32.5%;
  opacity: 0.5;
  background: #d6d6d6;
}
.digitRoll, .staticRoll
{
  width: 6.5%;
  height: 100%;
  background-color: #5a5a5a;
  color: #f8f8f8;
  text-align: center;
  outline: 0.5vh solid #ee7546;
  transition: background 0.2s ease-in;
}

.digitRoll.locked
{
  background: #63c463;
  pointer-events: none;
}

.digitRoll div, .staticRoll div
{
  width: 100%;
  transform: translateY(-43.5%);
  display: flex;
  flex-wrap: wrap;
  transition: transform 0.2s ease-in-out;
}

.digitRoll i, .staticRoll i
{
  font-size: 7vh;
  font-family: 'Megrim', cursive;
  line-height: 7vh;
  /*font-size: 5vh;
  font-family: 'Press Start 2P', cursive;*/
  width: 100%;
  height: 7vh;
  opacity: 1;
  font-style: normal;
  transition: all 0.3s ease-out;
}
            
          
!
            
              window.oncontextmenu = function(){return false};
var rolls = document.getElementsByClassName("digitRoll");
var solved = false;

for(var i = 0; i < rolls.length; i++)
{
  var digitWrapper = document.createElement('div');
  for(var j = 0; j < 12; j++)
  {
    var digit = document.createElement("i");
    digit.innerHTML = (j - 1 < 0) ? 9 : (j > 10) ? 0 : String(j-1);
    digitWrapper.appendChild(digit);
  }
  rolls[i].appendChild(digitWrapper);
  /*setTimeout(function(i){rollTo(rolls[i],i);}.bind(this,i),200*i);*/
  
  rolls[i].addEventListener("mousedown",function(e)
  {
    if(e.button == 2)
    rollTo(this,this.currentValue-1);
    else
    rollTo(this,this.currentValue+1);
  });
  
  rolls[i].addEventListener("wheel",function(e)
  {
    if(e.wheelDelta > 0)
    rollTo(this,this.currentValue-1);
    else
    rollTo(this,this.currentValue+1);
  });
}

function rollTo(pDigitRoll, pValue)
{
  //console.log(pDigitRoll,pValue);
  var digitslider = pDigitRoll.firstChild;
  var digits = digitslider.children;
  
  pValue = parseInt(pValue);
  pValue++;
  if(pValue > 10) pValue=1;
  if(pValue < 1) pValue=10;
  pDigitRoll.currentValue = pValue-1;
  
  digitslider.style.transform = "translateY(-"+(pValue*7+2)+"vh)";
  for(var i = 0; i < digits.length; i++)
  {
    digits[i].style.transform = "scaleY(0.1)";
    digits[i].style.opacity = 0.3;
  }
  if(pValue-1 >= 0)
  {
    digits[pValue-1].style.transform = "scaleY(0.5)";
    digits[pValue-1].style.opacity = 0.5;
  }
  else 
  {
    digits[digits.length-1].style.transform = "scaleY(0.5)";
    digits[digits.length-1].style.opacity = 0.5;
  }
  
  digits[pValue].style.transform = "scaleY(1)";
  digits[pValue].style.opacity = 1;
  
  if(pValue+1 <= digits.length-1)
  {
    digits[pValue+1].style.transform = "scaleY(0.5)";
    digits[pValue+1].style.opacity = 0.5;
  }
  else
  {
    digits[1].style.transform = "scaleY(0.5)";
    digits[1].style.opacity = 0.5;
  }
};

setInterval(function()
{
  var date = new Date();
  var h = String(date.getHours());
  var m = String(date.getMinutes());
  var s = String(date.getSeconds());
  //console.log(h+":"+m+":"+s);
  if(h.length < 2)
  {
    rollTo(rolls[0],0);
    rollTo(rolls[1],h);
  }
  else 
  {
    rollTo(rolls[0],h[0]); 
    rollTo(rolls[1],h[1]);
  }
  if(m.length < 2)
  {
    rollTo(rolls[2],0);
    rollTo(rolls[3],m);
  }
  else 
  {
    rollTo(rolls[2],m[0]); 
    rollTo(rolls[3],m[1]);
  }
  if(s.length < 2)
  {
    rollTo(rolls[4],0);
    rollTo(rolls[5],s);
  }
  else 
  {
    rollTo(rolls[4],s[0]); 
    rollTo(rolls[5],s[1]);
  }
  var y = String(date.getFullYear());
  for(var k = 0; k < 4; k++)
  {
    if(rolls[k+6].currentValue==y[k])rolls[k+6].classList.add("locked");
  }
  if(rolls[6].classList.contains("locked")&&
     rolls[7].classList.contains("locked")&&
     rolls[8].classList.contains("locked")&&
     rolls[9].classList.contains("locked")&&
     solved==false)
  {
    solved=true;
    setTimeout(function()
    {
      shuffleLock(3);
      solved=false;
    },3000);
  }
},1000);

function shuffleLock(pTimes,pLockRightNumbers)
{
  if(!pTimes)pTimes=0;
  for(var u = 6; u < 10; u++)
  {
    if(!rolls[u].classList.contains('locked')||(!pLockRightNumbers))
    {
      var r = Math.floor(Math.random()*9);
      rollTo(rolls[u],r);
      if(!pLockRightNumbers)rolls[u].classList.remove("locked");
    }
  }
  if(pTimes > 1)setTimeout(function(){shuffleLock(pTimes-1);},300);
}

rollTo(rolls[0],1);
rollTo(rolls[1],2);
rollTo(rolls[2],3);
rollTo(rolls[3],4);
rollTo(rolls[4],5);
rollTo(rolls[5],6);

rollTo(rolls[6],1);
rollTo(rolls[7],9);
rollTo(rolls[8],9);
rollTo(rolls[9],9);

var guessInterval;
document.getElementById("guess").addEventListener("change",
function(e)
{
  if(this.checked)
  {
    guessInterval = setInterval(function(){shuffleLock(0,true);},1000);
  }
  else
  {
    clearInterval(guessInterval);
  }
});
            
          
!
999px
Loading ..................

Console