1/*** 2@title: 3Vibrate 4 5@version: 62.0 7 8@author: 9Andreas Lagerkvist 10 11@date: 122008-08-31 13 14@url: 15http://andreaslagerkvist.com/jquery/vibrate/ 16 17@license: 18http://creativecommons.org/licenses/by/3.0/ 19 20@copyright: 212008 Andreas Lagerkvist (andreaslagerkvist.com) 22 23@requires: 24jquery 25 26@does: 27This plug-in makes any element you want "vibrate" every now and then. Can be used in conjunction with blink for maximum annoyance! 28 29@howto: 30jQuery('#ad-area').vibrate(); would make #ad-area vibrate every now and then, options are available, please check the source. 31 32Vibrate currently only works with elements positioned 'static'. 33 34@exampleHTML: 35I should vibrate every now and then 36 37@exampleJS: 38jQuery('#jquery-vibrate-example').vibrate(); 39***/ 40jQuery.fn.vibrate = function (conf) { 41 var config = jQuery.extend({ 42 start: 500, 43 speed: 30, 44 duration: 2000, 45 frequency: 5000, 46 spread: 3, 47 angle: 40, 48 }, conf); 49 50 return this.each(function () { 51 var t = jQuery(this); 52 53 t.data('stop', false); 54 55 var vibrate = function () { 56 var topPos = Math.floor(Math.random() * config.spread) - ((config.spread - 1) / 2); 57 var leftPos = Math.floor(Math.random() * config.spread) - ((config.spread - 1) / 2); 58 var rotate = Math.floor(Math.random() * config.angle) - ((config.angle - 1) / 2); 59 60 t.css({ 61 position: 'relative', 62 left: leftPos + 'px', 63 top: topPos + 'px', 64 WebkitTransform: 'rotate(' + rotate + 'deg)' // cheers to [email protected] for the rotation-idea 65 }); 66 }; 67 68 var doVibration = function () { 69 var vibrationInterval = setInterval(vibrate, config.speed); 70 71 var stopVibration = function () { 72 clearInterval(vibrationInterval); 73 t.css({ 74 position: 'static', 75 WebkitTransform: 'rotate(0deg)' 76 }); 77 }; 78 79 clearInterval(frequencyInterval); 80 81 if (t.data('stop') == true) { 82 clearInterval(vibrationInterval); 83 } 84 else { 85 frequencyInterval = setInterval(doVibration, config.frequency); 86 setTimeout(stopVibration, config.duration); 87 } 88 }; 89 90 frequencyInterval = setInterval(doVibration, config.start); 91 }); 92}; 93 94jQuery.fn.stopVibrate = function() { 95 return this.each(function () { 96 var t = jQuery(this); 97 98 t.data('stop', true); 99 }); 100};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.