Code Monkey home page Code Monkey logo

vue-typed-js's Introduction

vue-typed-js

npm npm vue2 Codacy Badge

A Vue.js integration for Typed.js.

Typed.js is a library that types. Enter in any string, and watch it type at the speed you've set, backspace what it's typed, and begin a new sentence for however many strings you've set.

Checkout the offical project here.

Table of contents

Installation

npm install --save vue-typed-js

Default import

Install the component:

import Vue from 'vue'
import VueTypedJs from 'vue-typed-js'

Vue.use(VueTypedJs)

⚠️ A css file is included when importing the package. You may have to setup your bundler to embed the css in your page.

Browser import

<link rel="stylesheet" href="vue-typed-js/dist/vue-typed-js.css"/>

<script src="vue.js"></script>
<script src="vue-typed-js/dist/vue-typed-js.browser.js"></script>

The plugin should be auto-installed. If not, you can install it manually with the instructions below.

Install all the components:

Vue.use(VueTypedJs)

Usage

To get started simply add the vue-typed-js custom element to your template and pass the text, which should be typed to the strings property. In addition you need to pass an element with the class typing to the slot, which will be used as a wrapper.

Minimal setup:

<vue-typed-js :strings="['First text', 'Second Text']">
  <h1 class="typing"></h1>
</vue-typed-js>

The typing class also allows you to just animate certain parts of a string:

<vue-typed-js :strings="['John', 'James']">
  <h1>Hey <span class="typing"></span></h1>
</vue-typed-js>

Properties

You can make use of the following properties in order to customize your typing expirience:

Property Type Description Usage
strings Array strings to be typed :strings="['Text 1', 'Text 2']"
stringsElement String ID of element containing string children :stringsElement="'myId'"
typeSpeed Number type speed in milliseconds :typeSpeed="50"
startDelay Number time before typing starts in milliseconds :startDelay="1000"
backSpeed Number backspacing speed in milliseconds :backSpeed="10"
smartBackspace Boolean only backspace what doesn't match the previous string :smartBackspace="true"
shuffle Boolean shuffle the strings :shuffle="true"
backDelay Number time before backspacing in milliseconds :backDelay="100"
fadeOut Boolean Fade out instead of backspace :fadeOut="true"
fadeOutClass String css class for fade animation :fadeOutClass="'fadeOutClass'"
fadeOutDelay Number fade out delay in milliseconds :fadeOutDelay="500"
loop Boolean loop strings :loop="true"
loopCount Number amount of loops :loopCount="3"
showCursor Boolean show cursor :showCursor="true"
cursorChar String character for cursor :cursorChar="'_'"
autoInsertCss Boolean insert CSS for cursor and fadeOut into HTML :autoInsertCss="true"
attr String attribute for typing Ex: input placeholder, value, or just HTML text :attr="'placeholder'"
bindInputFocusEvents Boolean bind to focus and blur if el is text input :bindInputFocusEvents="true"
contentType String 'html' or 'null' for plaintext :contentType="'html'"

Events

You can listen to the following events:

Event Description Usage
onComplete All typing is complete @onComplete="doSmth()"
preStringTyped Before each string is typed @preStringTyped="doSmth()"
onStringTyped After each string is typed @onStringTyped="doSmth()"
onLastStringBackspaced During looping, after last string is typed @onLastStringBackspaced="doSmth()"
onTypingPaused Typing has been stopped @onTypingPaused="doSmth()"
onTypingResumed Typing has been started after being stopped @onTypingResumed="doSmth()"
onReset After reset @onReset="doSmth()"
onStop After stop @onStop="doSmth()"
onStart After start @onStart="doSmth()"
onDestroy After destroy @onDestroy="doSmth()"

Features

Checkout features like type pausing, smart backspacing etc. on the libraries page.

Examples

Here are several examples:

<!-- infinite loop -->
<vue-typed-js :strings="['awesome', 'brilliant']" :loop="true" @onComplete="doSmth()">
  <h2>We are a <span class="typing"></span> company!</h2>
</vue-typed-js>

<!-- type pausing -->
<vue-typed-js :strings="['This is text ^1000 which gets paused for 1 second', 'wow, interesting']">
  <h2 class="typing"></h2>
</vue-typed-js>

<!-- output html -->
<vue-typed-js :strings="['<p>Paragraph</p>', '<span>Span</span>']" :contentType="'html'">
  <h2 class="typing"></h2>
</vue-typed-js>

License

MIT

vue-typed-js's People

Contributors

davidpmccormick avatar orlandster avatar ymhuang0808 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vue-typed-js's Issues

Events not working as expected

Hey,

Thanks for making this plugin - it's really useful for me. The only slight problem I'm having is getting some events to fire properly.

I'm using vue-typed-js in nuxt.js and when I use the @onstart method on my component, it does not get called before starting. The same is true with @preStringTyped and @onTypingResumed, although @onComplete works strangely enough.

Here is my VueTypedJs component:

        <vue-typed-js 
        :strings="['&nbsp;page&nbsp;', '&nbsp;link&nbsp;', '&nbsp;way&nbsp;']"
        :typeSpeed="100"
        :startDelay="1000"
        :showCursor=false
        @onStart="handleStart()"
        @preStringTyped="handleStart()"
        @onTypingResumed="handleStart()"
        @onComplete="handleComplete()"
        >
            <h1 class="text-5xl font-bold">One<span class="typing"></span>.to</h1>
        </vue-typed-js>

And the methods in the component are:

        handleStart() {
            alert('started')
        },
        handleComplete() {
            alert('completed')
        }

The only alert message I see is the completed one, which is annoying because I want to append an extra space to the word I'm inserting in between 2 other words before it starts typing.

I'm using it as plugin in nuxt like so:

Typed.js

import Vue from 'vue'
import VueTypedJs from 'vue-typed-js'

Vue.use(VueTypedJs)

Nuxt.config.js

  plugins: [
    { src: '~plugins/typed.js', ssr: false },
  ],

I have a feeling it may something be to do with #29 but I'm not sure.

Thanks for any help and again thanks for building a really useful plugin,
Isaac

line breaks are not detected

Hey! Thanks for the library. In the original typedJs library adding a line break \n within a string creates another line. In vue-typed-js it isn't working for me.

How do I place html content with class tags?

<vue-typed-js :strings="['word1', '<span class='text-white'>/</span>', '<span class='text-darkgrey text-mono my-2'>word2</span>' ]" :loop="true" :contentType='html'> <span class="typing"></span> </vue-typed-js>

maybe a bug

The text is stored in vuex, but when I refresh the page, the text disappears from the page unless I run the program again
In addition the text is obtained by sending a network request

showCursor property is not reactive

Hey! :)
Setting the showCursor property to true and then to false does not remove the cursor. Is that the expected behaviour? Is there a way to make it reactive?

i need help in the event

Hey, guys.

I need help to subscribe to the event, as I currently use a lib to perform string translation.

I make the request via router, in which I change the router and it does the simulated translation, however the strings inside the vue-typed are not translated, only when I give a reload on the page. I need help to carry out this simuntaneo translation, without needing to reload the page.

Here is a snippet of code so you can see my problem:

<vue-typed-js :strings="[$t('title_site.span_design'),$t('title_site.span_manage'),$t('title_site.span_dev')]" :backSpeed="100" :typeSpeed="100" :backDelay="1000"> <h1>{{ $t('title_site.message_think')}}<br/> {{ $t('title_site.aux_let') }} <span class="typing"></span> {{ $t('title_site.aux_us') }} </h1> </vue-typed-js>

Thank you and I'll be waiting.

How to stop events emitting after component is destroyed

Hey, love the library!

After implenting it on a project, I noticed that the module is emitting events in a loop even after the component which renders it is destroyed. How can I stop event triggers after I'm no longer on the page that features VueTypedJs?

Thanks!

Nuxtjs support

Is there any plans for supporting this library for Nuxtjs?

Problem installing

Hello,

in the package.json the typed.js dependency is written with the direct link to github instead of the version number.

"typed.js": "git+https://github.com/mattboldt/typed.js.git"

This creates a problem when using the library in CI or when using it as a dependency.

What do you think?

BackSpace not working

<vue-typed-js
            :strings="['idho Danang Sanyoto;']"
            :type-speed="150"
            :back-speed="20"
            :back-delay="100"
            :show-cursor="false"
            :fade-out="false"
            :loop="true"
          >
<h1 class="text-custom-title text-8xl py-4 -m-2">R<span class="typing"></span></h1>
<vue-typed-js>

the backspace effect not showing, it always fade out when the effect end

TypeError: s.trim is not a function

Hey,
After installing and running the plugin the following error is displayed

[Vue warn]: Error in nextTick: "TypeError: s.trim is not a function"

vue.runtime.esm.js?2b0e:1888 TypeError: s.trim is not a function
    at eval (typed.js?10b3:662)
    at Array.map (<anonymous>)
    at Initializer.load (typed.js?10b3:661)
    at new Typed (typed.js?10b3:92)
    at VueComponent.initTypedJS (TypedJS.vue?cdc7:26)
    at VueComponent.eval (TypedJS.vue?cdc7:16)
    at Array.eval (vue.runtime.esm.js?2b0e:1980)
    at flushCallbacks (vue.runtime.esm.js?2b0e:1906)

my code

<vue-typed-js :strings="['First text', 'Second Text']">
  <h1 class="typing"></h1>
</vue-typed-js>

vue => (cli) 3
node => v12.16.1

Events are emitted continuously after instantiation of the vue-typed-js component and navigating away (possible leak scenario)

I am nost sure if this is an issue of default behavior of vue/nuxt

I am using vue-typed-js on one of the pages in my nuxt website, and even when I navigate away from the page where I used this component, I see a lot of events continuously emitted by this package. Is that suppose to happen?

Screen Shot 2020-01-21 at 9 34 04 PM

These events were being emitted even when I only opened the home page.

My setup is as follows:

I added a file calledplugins/vue-typed-js.js

import Vue from 'vue';
import VueTypedJs from 'vue-typed-js';

Vue.use(VueTypedJs);

and in nuxt.config.js file I have

plugins: [
  {src: '@/plugins/vue-typed-js.js'},
]

I have this component being used in a page deep inside the route http://localhost:3000/projects/testProject and I can see the events even when I open the index.html at the root http://localhost:3000/ after I have opened the project page.

Is there any special way to destroy the component after navigating away?

Unable to bind dynamic data

:strings binds dynamic data and cannot be printed

<vue-typed-js :loop="true" :strings="[quote.content]" :type-speed="50" :back-speed="50">
  <span class="typing" />
</vue-typed-js>

Unknown custom element: <vue-typed-js>

I'm trying to use vue-typed-js but I get the following error: "Unknown custom element: ".

I've installed it via npm install --save vue-typed-js.

Inside the component in which I want to use Typed-js I've put

import Vue from 'vue';
import { VueTypedJs } from 'vue-typed-js';
Vue.use(VueTypedJs);

inside the script tag and:

<vue-typed-js :strings="['First text', 'Second Text']">
<h1 class="typing"></h1>
</vue-typed-js>

inside the template tag.

But it doesn't work.

Thank you.

Install instructions

Your "Default Import" section doesn't quite work for me. In order for the component to be recognized post entry-point, I had to import and use the entire module. I guess what I'm trying to say is that I think the default import snippet doesn't need brackets--e.g.

import Vue from 'vue'
import VueTypedJs from 'vue-typed-js'

Vue.use(VueTypedJs) 

Where to add :stringElement?

Hey,

try to set the :stringsElement in vue. Adding it inside the vue-typed-js, the error message comes "... Just one child element ...". Where do I have to add it?

<vue-typed-js 
:stringsElement="'myId'"
:typeSpeed="50"
>
<div id="myId">Some Text for typing-class</div>
  <h1 class="typing"></h1>
</vue-typed-js>

Doesn’t work when loop and smartBackspace are true

Hi, thanks so much for your work on this.

As noted in the title, the animation breaks after one cycle with both :loop="true" and smartBackspace="true" configured.

e.g.

    <vue-typed-js
      :strings="['Any Old Bollocks', 'Any Other Business', 'Await Orthogonal Blessings', 'Abraham Object Bison', 'About Occasionally Beloved', 'Adolescent Orangutan Bicycles']"
      :typeSpeed="100"
      :startDelay="1000"
      :backSpeed="20"
      :smartBackspace="false"
      :shuffle="true"
      :loop="true"
      :showCursor="false"
    >
      <h1 class="typing"></h1>
    </vue-typed-js>

I believe this was fixed in the original package, as mentioned here: mattboldt/typed.js#262 (comment)

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.