balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

effect-shake.js (1832B)


      1 /*!
      2  * jQuery UI Effects Shake 1.12.1
      3  * http://jqueryui.com
      4  *
      5  * Copyright jQuery Foundation and other contributors
      6  * Released under the MIT license.
      7  * http://jquery.org/license
      8  */
      9 
     10 //>>label: Shake Effect
     11 //>>group: Effects
     12 //>>description: Shakes an element horizontally or vertically n times.
     13 //>>docs: http://api.jqueryui.com/shake-effect/
     14 //>>demos: http://jqueryui.com/effect/
     15 
     16 ( function( factory ) {
     17 	if ( typeof define === "function" && define.amd ) {
     18 
     19 		// AMD. Register as an anonymous module.
     20 		define( [
     21 			"jquery",
     22 			"./effect"
     23 		], factory );
     24 	} else {
     25 
     26 		// Browser globals
     27 		factory( jQuery );
     28 	}
     29 }( function( $ ) {
     30 
     31 return $.effects.define( "shake", function( options, done ) {
     32 
     33 	var i = 1,
     34 		element = $( this ),
     35 		direction = options.direction || "left",
     36 		distance = options.distance || 20,
     37 		times = options.times || 3,
     38 		anims = times * 2 + 1,
     39 		speed = Math.round( options.duration / anims ),
     40 		ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
     41 		positiveMotion = ( direction === "up" || direction === "left" ),
     42 		animation = {},
     43 		animation1 = {},
     44 		animation2 = {},
     45 
     46 		queuelen = element.queue().length;
     47 
     48 	$.effects.createPlaceholder( element );
     49 
     50 	// Animation
     51 	animation[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance;
     52 	animation1[ ref ] = ( positiveMotion ? "+=" : "-=" ) + distance * 2;
     53 	animation2[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance * 2;
     54 
     55 	// Animate
     56 	element.animate( animation, speed, options.easing );
     57 
     58 	// Shakes
     59 	for ( ; i < times; i++ ) {
     60 		element
     61 			.animate( animation1, speed, options.easing )
     62 			.animate( animation2, speed, options.easing );
     63 	}
     64 
     65 	element
     66 		.animate( animation1, speed, options.easing )
     67 		.animate( animation, speed / 2, options.easing )
     68 		.queue( done );
     69 
     70 	$.effects.unshift( element, queuelen, anims + 1 );
     71 } );
     72 
     73 } ) );