baffle.js

一个小型 javascript 库,用于在 DOM 元素中混淆和显示文本。「A tiny javascript library for obfuscating and revealing text in DOM elements. 」

Github星跟蹤圖

baffle.js

A tiny javascript library for obfuscating and revealing text in DOM elements.

camwiegert.github.io/baffle

  • ~1.8kb gzipped :zap:
  • Dependency-free :tada:
  • IE9+ :heavy_check_mark:
// Select elements and start.
const b = baffle('.someSelector').start();

// Do something else.
someAsyncFunction(result => {
    // Change the text and reveal over 1500ms.
    b.text(text => result.text).reveal(1500);
});

Getting Started

Step 0: Install

Download the latest release or install with npm.

npm install --save baffle

Step 1: Reference

If you linked baffle directly in your HTML, you can use window.baffle. If you're using a module bundler, you'll need to import baffle.

// CommonJS
const baffle = require('baffle');

// ES6
import baffle from 'baffle';

Step 2: Initialize

To initialize baffle, all you need to do is call it with some elements. You can pass a NodeList, Node, or CSS selector.

// With a selector.
const b = baffle('.baffle');

// With a NodeList
const b = baffle(document.querySelectorAll('.baffle'));

// With a Node
const b = baffle(document.querySelector('.baffle'));

Step 3: Use It

Once you have a baffle instance, you have access to all of the baffle methods. Usually, you'll want to b.start() and, eventually, b.reveal().

// Start obfuscating...
b.start();

// Or stop obfuscating...
b.stop();

// Obfuscate once...
b.once();

// You can set options after initializing...
b.set({...options});

// Or change the text at any time...
b.text(text => 'Hi Mom!');

// Eventually, you'll want to reveal your text...
b.reveal(1000);

// And they're all chainable...
b.start()
    .set({ speed: 100 })
    .text(text => 'Hi dad!')
    .reveal(1000);

Options

You can set options on baffle during initialization or anytime afterward with baffle.set().

// During initialize
baffle('.baffle', {
    characters: '+#-•=~*',
    speed: 75
});

// Any time with set()
b.set({
    characters: '¯\_(ツ)_/¯',
    speed: 25
});

options.characters

The characters baffle uses to obfuscate your text. It can be a string or an array of characters.

Default: `'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz~!@#$%^&*()-+=[]{}

主要指標

概覽
名稱與所有者camwiegert/baffle
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台Web browsers
許可證MIT License
所有者活动
創建於2016-07-19 03:07:17
推送於2017-08-28 06:48:41
最后一次提交2017-03-29 14:16:51
發布數0
用户参与
星數1.8k
關注者數22
派生數84
提交數109
已啟用問題?
問題數31
打開的問題數0
拉請求數6
打開的拉請求數0
關閉的拉請求數8
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?