key type chatbox hint

by Jayson Buquia

HTML

<link rel="preload" href="https://ilogistis.gr/ilogistis/img/dotsW.gif">

<div id="chatbox"></div>
<input type="text" id="input">

SCSS

#input {  
  width: 50%;
  padding: 8px 5px;
  box-sizing: border-box;
}

#chatbox {
  border: 1px solid gray;
  border-radius: 2px;
  width: 50%;
  min-height: 200px;
  margin-bottom: 50px;
  position: relative;
 
    &:after {
      content: '';
      background-image: url('https://ilogistis.gr/ilogistis/img/dotsW.gif');
      background-size: cover;
      background-position: center center;
      width: 50px;
      height: 30px;
      position: absolute;
      bottom: 10px;
      left: 10px;
      pointer-events: none;
      opacity: 0;
      transition: all .3s ease;
    }
  
   &[data-loading] {
     &:after {
       opacity: 1;
     }
   }
  
}

JavaScript

$('#input').each(function(){

	var $el = $(this),
  		$chatbox = $('#chatbox'),
      hintTimeout;
  
  $el.on('keypress',function(){
  
  	clearTimeout(hintTimeout);
  
  	$chatbox[0].setAttribute('data-loading',true);  
    hintTimeout = setTimeout(function(){
    	$chatbox[0].removeAttribute('data-loading'); 
    },1000);    
    
  }); 		
  
});