LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code
CSS Containment Demo
CSS
article {
  flex: 1;
  padding: 16px;
  display: block;
  box-sizing: border-box;
  overflow-y: auto;
  will-change: transform;
}

article.optimized {
  contain: layout size;
}

article > div {
  width: calc(100% - 32px);
  height: 100px;
  margin: 16px;
  float: left;
  background-color: white;
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  box-sizing: border-box;
  box-shadow: 0 0 3px 0 rgba(0,0,0,0.4);
  font-size: 3rem;
  line-height: 1;
  color: rgba(0,0,0,0.1);
  font-family: serif;
}
JS
const content = document.querySelector('article');

var counter = 0;
var timer = 0;

function start() {
  clear();

  timer = setInterval(() => {
    if (counter >= 9) {
      stop();
    }

    requestAnimationFrame(() => {
      requestAnimationFrame(appendElement);
    });
  }, 300);
}

function stop() {
  clearInterval(timer);  
}

function clear() {
  stop();
  counter = 0;
  content.innerHTML = '';
}

function appendElement() {
  let div = document.createElement('div');
  div.textContent = ++counter;
  content.appendChild(div);
  div = null;
}

function enableContainment() {
  content.classList.add('optimized');
}

function disableContainment() {
  content.classList.remove('optimized');
}


const enButton = document.querySelector('#enablebutton');
const diButton = document.querySelector('#disablebutton');
const playButton = document.querySelector('#playbutton');

enButton.addEventListener('change', enableContainment);
diButton.addEventListener('change', disableContainment);
playButton.addEventListener('click', start);
Term
Sat, 01/13/2018 - 07:27

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv