-
Notifications
You must be signed in to change notification settings - Fork 3
/
jquery.vibrate.min.js
21 lines (21 loc) · 2.93 KB
/
jquery.vibrate.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
* jquery.vibrate.js
* jQuery Vibrating Button Plugin
*
* Author: Alberto Arena <[email protected]>
* Version: 1.2
* Date: 16/03/2013
* Demo: http://www.dev4web.eu/projects/jquery.vibrate
* Support: https://github.com/albertoarena/jQuery-Vibrate
*
* Changelog
* 1.2 16 mar 2013: optimized code and improved speed
* 1.1 29 oct 2011: added vibrateClass and overClass parameters
* 1.0.1 17 dec 2010: removed "overflow:hidden" attribute to both wrapping DIVS (to allow transparency outside the vibrating box); added overEffect parameter
* 1.0 14 dec 2010: released first version
*/
(function(b){b.fn.vibrate=function(f){b(this).each(function(){var a=b(this);"undefined"==b.type(a.attr("id"))&&a.attr("id","vibrate_"+Math.round(1E17*Math.random()));a.id=a.attr("id");a.defaults={reverse:!1,speed:50,trigger:"mouseover",overEffect:"stop",overClass:"",vibrateClass:""};a.defaults=b.extend(a.defaults,f);a.defaults.speedBackup=a.defaults.speed;a.data("vibrate",a);a.data("vibrate.status",!1);var c=a.outerWidth(),e=a.outerHeight(),d={"float":a.css("float"),margin:a.css("margin-top")+" "+
a.css("margin-right")+" "+a.css("margin-bottom")+" "+a.css("margin-left"),display:a.css("display"),width:c,height:e,padding:"0",border:"0"},c={width:c,height:e,padding:"0",margin:"0",border:"0",display:"block"};a.wrap("<div><div></div></div>");a.parent().css(c);a.parent().parent().css(d);a.css({margin:"0"});d="";"mouseover"==a.defaults.trigger?d="mouseout":"focus"==a.defaults.trigger&&(d="blur");"stop"!=a.defaults.overEffect&&"invert"!=a.defaults.overEffect&&(a.defaults.overEffect="");a.defaults.reverse?
(""!=a.defaults.overEffect&&a.bind(a.defaults.trigger,function(){a.addClass(a.defaults.overClass);"stop"==a.defaults.overEffect?a.vibrationStop():"invert"==a.defaults.overEffect&&(a.defaults.speed=Math.round(a.defaults.speed/3))}).bind(d,function(){a.removeClass(a.defaults.overClass);"invert"==a.defaults.overEffect?a.defaults.speed=a.defaults.speedBackup:a.vibrationStart()}),setTimeout(function(){a.vibrationStart()},Math.round(100*Math.random))):a.bind(a.defaults.trigger,function(){a.vibrationStart()}).bind(d,
function(){a.vibrationStop()})});b.fn.vibrationStart=function(){var a=b(this);"undefined"!==b.type(a.data("vibrate"))&&(a.data("vibrate.status",!0),a.css({margin:"0 0 0 0"}),a.addClass(a.data("vibrate").defaults.vibrateClass),a.vibrationLoop())};b.fn.vibrationStop=function(){var a=b(this);"undefined"!==b.type(a.data("vibrate"))&&(a.stop(!1,!0),a.removeClass(a.data("vibrate").defaults.vibrateClass),a.data("vibrate.status",!1))};b.fn.vibrationLoop=function(){var a=b(this);if("undefined"!==b.type(a.data("vibrate")))if(!0==
a.data("vibrate.status")){var c={marginTop:0,marginLeft:0};a.position();0<parseInt(a.css("marginTop"))?(c.marginTop="-1px",c.marginLeft="-1px"):(c.marginTop="1px",c.marginLeft="1px");a.animate(c,a.data("vibrate").defaults.speed,function(){a.vibrationLoop()})}else a.css({margin:"0 0 0 0"})}}})(jQuery);