C
C
chelovekfrontend2019-04-15 15:57:44
css
chelovekfrontend, 2019-04-15 15:57:44

How to catch the scroll event of the textarea field?

Can you please tell me how to catch the scroll event of the textarea field?
Suppose there is a textarea field, it has overflow: auto, at some point in time (when the textarea field is filled) a scroll appears, when it appears, I need the desired method to work.
Example (fictitious), textarea scroll appeared, padding property was added to the textarea tag: 10px;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Luzanov, 2019-04-15
@mrister_chelovek

@Directive({
  selector: 'textarea[appText]'
})
export class TextDirective {
  @Output() public hasScrollBar = new EventEmitter<boolean>();

  constructor(private readonly elRef: ElementRef<HTMLTextAreaElement>) {}

  @HostListener('change')
  @HostListener('input')
  public changes() {
    const elem = this.elRef.nativeElement;
    this.hasScrollBar.emit(elem.clientHeight < elem.scrollHeight);
  }
}

<textarea appText (hasScrollBar)="print($event)"></textarea>

A
Andrej Sharapov, 2019-04-15
@Madeas

Try so maybe

const 
txt = document.getElementById("text"),
txts = txt.style.height,
pd = '70px';

console.log(pd);

if (txts !== pd) {
  txt.style.background = "black";
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question