0

I'm trying to replicate the functionality found in this codepen example.

Primarily, I'd like to include this code:

$( function() {

  var $wrap = $('#wrap');
    var $textarea = $('textarea');
  var $dummy = $('.dummy');


  function positionTextarea() {
    var h = $wrap.height();
    var top = Math.max( 0, ( h - $dummy.height() ) * 0.5 );
    $textarea.css({
      paddingTop: top,
      height: h - top
    });
  }

  $textarea.on( 'keyup change', function( event ) {
    var html = formatDummyText( $textarea.val() );
    $dummy.html( html );
        positionTextarea();
  }).trigger('change');

  // should debounce this
  $( window ).on( 'resize', positionTextarea );

});

in a directive. I'll have a textarea with a dummy div nearby with 0 opacity. What's the best way to include this functionality in a directive?

opticon
  • 3,494
  • 5
  • 37
  • 61
  • The best way to include this in a directive is to create a directive and include this on it. Are you asking us to make it for you? Try something and ask a question if you face a problem. – floribon Apr 03 '15 at 01:18
  • In a Directive you should be changing your Data using events and jQuery, in a Directive you should bind the data changed using [ng-model](https://docs.angularjs.org/api/ng/directive/ngModel) you can check this [example](http://stackoverflow.com/questions/14115701/angularjs-create-a-directive-that-uses-ng-model) to use it on directives – Matias Fernandez Martinez Apr 03 '15 at 01:22

0 Answers0