V
V
Vladimir Babin2014-02-11 16:24:08
JavaScript
Vladimir Babin, 2014-02-11 16:24:08

How to implement text hiding (cat, cut) in Javascript?

I liked the implementation of hiding text in VKontakte.
gJcGPfj.png
Are there any libraries or ready-made functions for this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Babin, 2014-02-11
@chiliec

In the end, I wrote it myself. If anyone is interested:

widget.onload = function(){
  block = document.getElementById('content');
  block_height =  block.style.height ? block.style.height : block.offsetHeight;
  
  if(block_height > 180){
    block.style.maxHeight = '180px';
    link = document.getElementById('read-next');
    link.style.display = 'inline'; 
          
    link.onclick = function(){
      block.style.maxHeight = '';
      link.innerHTML = 'Читать далее...';    
      link.style.display = 'none';
      skyscraper();
      return false;
    }
  }
}
You can see it in work here: www.yandex.ru/?add=157239

K
Konstantin Kitmanov, 2014-02-11
@k12th

details + polyfill.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question