GithubHelp home page GithubHelp logo

lkmill / jquery-enter-leave Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 11 KB

jQuery plugin for animating DOM insertions and removals (inspired by ngAnimate functionality).

License: MIT License

JavaScript 100.00%

jquery-enter-leave's Introduction

jquery-enter-leave

Simplifies animating elements added or removed to the DOM. Greatly inspired by functionality in Angular's ngAnimate.

Introduction

Exposes two functions on jQuery instances, enter and leave. enter should be used to animate inserts into the DOM, and leave is used to animate removals.

Install

npm install jquery-enter-leave

Simply make sure to require('jquery-enter-leave') to load the plugin. If you want to load the toggle, show and hide methods, also require('jquery-enter-leave/toggle').

enter and leave

Sample JS:

$('main > .page').leave(options);

page.enter($('main'), options, function() {
	console.log('done');
});

Sample SCSS:

main {
	@include clear;
	flex: 1 0 auto;
	overflow-x: hidden;//needed to fix chrome animation bug (logo seems to move);

	> .page {
		width: 100%;
		position: relative;
		left: 0;
		&.animate {
			transition: left $transition-time;
			float: left;
			margin-right: -100%;
		}
		&.enter {
			left: 100%;
			&.back {
				left: -100%;
			}
		}

		&.leave.active {
			left: -100%;
			&.back {
				left: 100%;
			}
		}
		&.enter.active, &.leave {
			left: 0;
		}
	}
}

toggle, show and hide

The jquery-enter-leave/toggle module overwrites the default toggle, show and hide methods. However, the custom logic is only used if !!options.transition === true, otherwise control will be passed over the original method.

$('.question').on('click', function() {
	$(this).next('.answer').toggle({ transition: true });
});

CAUTION!: jQuery will call this.animate inside these methods if an object is passed as a parameter. So passing enter-leave options but forgetting to pass transtion: true will call jQuery's animate. IE do not do (for example) $el.show({ animateHeight: true }).

className

A custom class to add and remove.

animateHeight

Since animating to height: auto with CSS is not possible, one needs to pass the animateHeight: true. This will set some inline CSS, using $(this).css('height', this.scrollHeight);.

Sample SCSS:

&.animate {
	transition: height 0.5s;
}

&.enter:not(.active), &.leave.active {
	height: 0 !important;
}

jquery-enter-leave's People

Contributors

lkmill avatar vicgeralds avatar

Watchers

James Cloos avatar  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.