layervault / jquery.typer.js

A simple jQuery plugin for a slick typing effect.
743 stars 103 forks source link

callback function #6

Open mattcasey opened 11 years ago

mattcasey commented 11 years ago

would be nice to have some way to call a function after typing is done. I edited 3 places, now I can set $.typer.options.OnDoneTyping before the typing begins Line 14:

  var
    options = {
      highlightSpeed    : 20,
      typeSpeed         : 100,
      clearDelay        : 500,
      typeDelay         : 200,
      clearOnHighlight  : true,
      typerDataAttr     : 'data-typer-targets',
      typerInterval     : 2000,
      OnDoneTyping      : null
    },

Line 77:

    if (!text || text.length === 0) {
      clearData($e);
      onDoneTyping();
      return;
    }

Line 258:

  onDoneTyping = function () {
    if(typeof $.typer.options.OnDoneTyping == 'function') {
      $.typer.options.OnDoneTyping();
    }
  };
bbirand commented 10 years ago

Would be good to have this merged..

KeeyaWangJones commented 9 years ago

Hi, I am trying to allow the user to pause and play the typer so that it is not distracting to the other content on the website. I tried adding an option and calling it with your method. Tweaked with jQuery pause and play.

var options = {
      highlightSpeed    : 20,
      typeSpeed         : 100,
      clearDelay        : 500,
      typeDelay         : 200,
      clearOnHighlight  : true,
      typerDataAttr     : 'data-typer-targets',
      typerInterval     : 2000,
      OnDoneTyping      : null,
      PausePlayTyping: null
    },
 if (!text || text.length === 0) {
      clearData($e);
      PausePlayTyping();
      return;
    }
PausePlayTyping = function () {
      $('.typer').click(function() {
          if (this.paused == false) {
          this.pause();
          alert('typer paused');
       } else {
         this.play();
         alert('typer playing');
       }
     })
};

Or is there a pause/play toggle already built into the plugin? If so, how do I call it?