1.1.4 • Published 1 year ago

floating-placeholder v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Floating Placeholder

A simple javascript package allows to show/hide a label during input to a text field to always show a placeholder.

Installation

npm install floating-placeholder

Usage

This package adds active class to your <label> element then <input> isn't empty and remove active class otherwise.

<div>
  <label for="input">Name</label>
  <input type="text" id="input" placeholder="Name">
</div>
import FloatingPlaceholder from 'floating-placeholder';

new FloatingPlaceholder( {
  element: document.getElementById( 'input' ), // required
  activeClass: "active" // "active" by default
} );

The package only adds active class, so you can style it however you want.

label {
  opacity: 0;
  display: block;
  transition: opacity .3s;
}

label.active {
  opacity: 1;
}

Mass applying by selector

<div>
  <label for="input">Name</label>
  <input type="text" id="input" placeholder="Name">
</div>
<div>
  <label for="textarea">Message</label>
  <textarea id="textarea" placeholder="Message"></textarea>
</div>
import FloatingPlaceholder from 'floating-placeholder';

let elements = document.querySelectorAll('input, textarea');

elements.forEach( el => new FloatingPlaceholder({
  element: el
}) );
1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago