Code Monkey home page Code Monkey logo

paper-ripple's Introduction

mutation-watcher
PaperRipple v0.3.0

Build Status Code Climate Dependency Status ESDoc Coverage

Material Design Ripple effect in pure JS & CSS.

PaperRipple lets you add a Material Design ripple effect to UI elements.

๐Ÿ“€ Install

Bower:
$ bower install paper-ripple
NPM:
$ npm install paper-ripple --save

How it looks like

Live example at codepen.

๐Ÿ“‹ Usage

First, you need to include PaperRipple JS and CSS files to your HTML-page.

Assume, you have next HTML:

<button class="paper-button">button</button>
<button class="paper-button blue-text">button</button>
<button class="paper-button orange-text">button</button>

Your JS will look like:

// // Getting all the buttons
var button = document.querySelectorAll('button.paper-button');

// Traversing the buttons
[].forEach.call(buttons, function(button) {
	// New PaperRipple for the button
	var ripple = new PaperRipple();
	
	// Adding ripple container to the button
	button.appendChild(ripple.$);

	// Subscribing to 'mousedown' and 'mouseup' button events to activate ripple effect
	// when a user clicks on the button.
	button.addEventListener('mousedown', function(ev) {
		ripple.downAction(ev);
	});
	button.addEventListener('mouseup', function() {
		ripple.upAction();
	});
});

NOTE: It's important that each element you add the ripple to must be relative position.

If you prefer to work with modules in JS, PaperRipple exports itself in AMD, CommonJS and as global variable if no require or module were found. In addition, under dist\systemjs you may find PaperRipple as SystemJS module.

Even more, if you prefer to work with jQuery you may find jQuery plugin based on PaperRipple under dist folder. So, the previous example may be simplified to the next:

$('button.paper-button').paperRipple();

Configuration

You may pass additional options to the constructor to control PaperRipple behavior:

var ripple = new PaperRipple(cfg);

If you have DOM element you want to use as PaparRipple element, pass it to the constructor. But be careful, PaperRipple element must follow next structure:

<div class="paper-ripple">
	<!-- optional -->
	<div class="paper-ripple__background"></div>

	<!-- optional -->
	<div class="paper-ripple__waves"></div>
</div>
var rippleEl = document.querySelector('.paper-ripple'),
	ripple = new PaperRipple(rippleEl);

assert(ripple.$ === rippleEl); // true

Or you may pass object containing next options:

  • initialOpacity: Number - Defaults to 0.25. The initial opacity of the each wave.
  • opacityDecayVelocity: Number - Defaults to 0.8. How fast (opacity per second) the wave fades out.
  • recenters: Boolean - Defaults to false. If true, waves will exhibit a gravitational pull towards the center of their container as they fade away.
  • center: Boolean - Defaults to false. If true, waves will center inside its container.
  • round: Boolean - Defaults to false. If true, ripple effect will apply within a circle.
  • target: HTMLElement - Defaults to null. Target DOM element as the container for the waves.
var ripple = new PaperRipple({
	initialOpacity: 0.3,
	recenters: true
});

Each of these options may be changed after initializing:

ripple.center = true;
ripple.opacityDecayVelocity = 0.7;

NOTE: Changing of $, $background or $waves after initialization not recommended.

Styling

Use CSS color property to style the ripple:

.paper-ripple {
	color: #FF9800;
}

NOTE: CSS color property is inherited so it is not required to set it on the .paper-ripple directly.

๐Ÿ“— Browser Support

  • Chrome
  • Firefox
  • Safari
  • Opera
  • IE9+

NOTE: IE9 doesn't support classList on HTMLElement object and requestAnimationFrame. You need to polyfill it. My choice: classList - bower install classlist or npm install classlist-polyfill; requestAnimationFrame - bower install window.requestanimationframe or npm install window.requestanimationframe.

๐ŸŽ“ Docs

PaperRipple JS has an excellent documentation. Esdoc is used to generate it. To generate it by yourself do following:

Clone the repo:

$ git clone https://github.com/virtyaluk/paper-ripple.git

Install dependencies:

$ npm install -g gulp && npm install

Generate the docs:

$ gulp docs

Docs will be available under docs folder in the root of the project.

Running tests

Install dependencies:

$ npm install

Run them:

$ gulp test

๐Ÿ“† Changelog

0.2.0 (December 07, 2015)

  • Added new round property on main PaperRipple class.

0.3.0 (June 01, 2017)

๐Ÿ“— License

Licensed under the MIT license.

Copyright (c) 2017 Bohdan Shtepan


modern-dev.com ย ยทย  GitHub @virtyaluk ย ยทย  Twitter @virtyaluk

paper-ripple's People

Contributors

brianfryer 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

paper-ripple's Issues

when mouse up outside of element

sorry for bad english...

when I mouse down an element, wave appears
then drag out of element and mouseUp, the wave remains.

repeat this it will be darken.

screen shot 2018-09-12 at 6 05 16 pm

DevTools failed to parse SourceMap

hey,

if I include this file dist/PaperRipple.js I get the following error in my command line.

DevTools failed to parse SourceMap: http://localhost:8000/components/paper-ripple/dist/PaperRipple.js.map

maybe a wrongly created SourceMap file?

Naming issue paper-ripple

hey,

congrats to this nice ripple effect - I would like to incorporate it into my custom element. But for Custom elements there is already an element by polymer that uses the same name and folder... and as in the web (with bower) there can only be ONE paper-ripple folder it comes to to a clash :/

this is the element in question
https://www.webcomponents.org/element/PolymerElements/paper-ripple

I'm not sure howto solve that maybe rename to "paper-ripple-class"?

for now I sadly have to copy the code and can't use bower dependencies...

Dynamic elements paper-ripple

Awesome plugin Virtyaluk. Although I'm facing a problem here now.
How do you handle dynamic elements?

el.addEventListener('mousedown', function(ev) {
    this.PaperRipple.downAction(ev);
});
el.addEventListener('mouseup', function() {
    this.PaperRipple.upAction();
});

I've tried some DOM listeners then check if event was on "el" but had no success in any of my attempts so far.

Not supports IE browsers?

image

The PaperRipple examples in Codepen is good, but when I use npm install paper-ripple to install latest version 0.2.0, seems not work at IE 11

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.