Giter Club home page Giter Club logo

malarkey's Introduction

malarkey npm Version Build Status Coverage Status

Simulate a typewriter effect in vanilla JavaScript.

  • Flexible API allowing granular control
  • Option to repeat the sequence indefinitely
  • Allows stopping and resuming the sequence on-the-fly
  • 524 bytes gzipped

Usage

Editable demo (CodePen)

<div class="typewriter"></div>
const malarkey = require('malarkey')

const element = document.querySelector('.typewriter')
function callback (text) {
  element.textContent = text
}
const options = {
  typeSpeed: 50,
  deleteSpeed: 50,
  pauseDuration: 2000,
  repeat: true
}
malarkey(callback, options)
  .type('Say hello')
  .pause()
  .delete()
  .type('Wave goodbye')
  .pause()
  .delete()

API

const malarkey = require('malarkey')

const m = malarkey(callback [, options])

Initialise the typewriter effect with the given optional options settings.

  • callback is a function that is invoked for every type and delete event in the sequence. The function signature is (text), where text is the string of characters that have been typed so far.

  • options is an object literal:

    Key Description Default
    typeSpeed Duration in milliseconds to type a single character 50
    deleteSpeed Duration in milliseconds to delete a single character 50
    pauseDuration Duration in milliseconds to pause 2000
    repeat Whether to repeat the entire sequence indefinitely false

m.type(string [, options])

Type the given string, one character at a time.

  • Set options.speed to override the default typeSpeed.

m.delete([characterCount, options])

Delete the specified number of characters, one character at a time.

  • characterCount is a positive integer. If not specified, all characters previously typed will be deleted, one character at a time.
  • Set options.speed to override the default deleteSpeed.

m.pause([options])

Do nothing for some duration.

  • Set options.duration to override the default pauseDuration.

m.clear()

Immediately clear all characters that were typed.

m.call(fn)

Call the given fn function.

  • The function signature of fn is (callback, text). Invoke callback to signal that fn has finished execution and that we can move on to the next event in the sequence.

m.triggerStop([fn])

Stops the sequence. Calls the given fn function when the sequence has been stopped.

  • The function signature of fn is (text).

m.triggerResume()

Resume the sequence. Has no effect if the sequence is already running.

m.isStopped()

Returns true if the sequence is currently stopped, else returns false.

Installation

Install via yarn:

$ yarn add malarkey

Or npm:

$ npm install --save malarkey

License

MIT

malarkey's People

Contributors

stefanoverna avatar yuanqing avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.