A Pen by Lucas Campos

Thumbnail
This awesome code was written by lucascampos, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright lucascampos ©
  • HTML
  • CSS
  • JavaScript
    <div></div>

/*Downloaded from https://www.codeseek.co/lucascampos/a-pen-by-lucas-campos-POJNwv */
    div {
  width: 120px;
  height: 40px;
  background-color: red;
  position: absolute;
  top: 20px;
  left: 0px;
}


/*Downloaded from https://www.codeseek.co/lucascampos/a-pen-by-lucas-campos-POJNwv */
    var div = document.querySelector('div');

document.addEventListener('keydown', function(event) {
  if(event.keyCode==39) {    
    div.style.left = div.offsetLeft + 5 + 'px';
  }
})

div.clicked = false;

div.addEventListener('click', function(e) {
  div.clicked=!div.clicked;
  if(div.clicked) {
    div.style.background = 'green';  
  } else {
    div.style.background = 'blue';
  }
});

Comments