/*! * jQuery UI Effects Shake 1.12.1 * http://jqueryui.com * * Copyright jQuery Foundation and other contributors * Released under the MIT license. * http://jquery.org/license */ //>>label: Shake Effect //>>group: Effects //>>description: Shakes an element horizontally or vertically n times. //>>docs: http://api.jqueryui.com/shake-effect/ //>>demos: http://jqueryui.com/effect/ function shaker(element){ element = $(element); if (element.length === 0 || typeof element.queue !== 'function') { console.error("Element does not exist or method 'queue' is not supported"); return; } var i = 1, direction = "left", distance = 10, times = 3, anims = times * 2 + 1, speed = 75, ref = ( direction === "up" || direction === "down" ) ? "top" : "left", positiveMotion = ( direction === "up" || direction === "left" ), animation = {}, animation1 = {}, animation2 = {}, queuelen = element.queue().length; // Animation animation[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance; animation1[ ref ] = ( positiveMotion ? "+=" : "-=" ) + distance * 2; animation2[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance * 2; // Animate element.animate( animation, speed); // Shakes for ( ; i < times; i++ ) { element .animate( animation1, speed) .animate( animation2, speed); } element .animate( animation1, speed) .animate( animation, speed / 2) }