Vibrate 2.0

Created Sunday 31st of August 2008 by Andreas Lagerkvist
Copyright © 2008 Andreas Lagerkvist (andreaslagerkvist.com)

Please have a look at the "Other Resources" for bug reports or further help on jQuery. Do not post bug reports or feature requests as comments to unrelated articles. If bug reporting on bugtracker.a-framework.org fails, e-mail me.

What it Does

This plug-in makes any element you want "vibrate" every now and then. Can be used in conjunction with blink for maximum annoyance!

How to Use

jQuery('#ad-area').vibrate(); would make #ad-area vibrate every now and then, options are available, please check the source.

Vibrate currently only works with elements positioned 'static'.

Example

I should vibrate every now and then

Example Code

HTML

<div id="jquery-vibrate-example">
I should vibrate every now and then
</div>

JS

jQuery('#jquery-vibrate-example').vibrate();

Source Code

jQuery.fn.vibrate = function (conf) {
    var 
config jQuery.extend({
        
speed:        30
        
duration:    2000
        
frequency:    5000
        
spread:        3
    
}, conf);

    return 
this.each(function () {
        var 
jQuery(this);

        var 
vibrate = function () {
            var 
topPos    Math.floor(Math.random() * config.spread) - ((config.spread 1) / 2);
            var 
leftPos    Math.floor(Math.random() * config.spread) - ((config.spread 1) / 2);
            var 
rotate    Math.floor(Math.random() * config.spread) - ((config.spread 1) / 2);

            
t.css({
                
position:            'relative'
                
left:                leftPos 'px'
                
top:                topPos 'px'
                
WebkitTransform:    'rotate(' rotate 'deg)'  // cheers to erik@birdy.nu for the rotation-idea
            
});
        };

        var 
doVibration = function () {
            var 
vibrationInterval setInterval(vibrateconfig.speed);

            var 
stopVibration = function () {
                
clearInterval(vibrationInterval);
                
t.css({
                    
position:            'static'
                    
WebkitTransform:    'rotate(0deg)'
                
});
            };

            
setTimeout(stopVibrationconfig.duration);
        };

        
setInterval(doVibrationconfig.frequency);
    });
};

Download

Plug-in

Requires

Random jQuery Plug-ins

  • Slide Presentation

    A sort of slide/presentation kind of plug-in. Displays sliding images with text floating on top. This one's pretty specific but perhaps someone will f...

    Details

  • Tag Sizes

    Use this plug-in on a list of tags (li:s) and it will use whatever numbers found in the list to give each tag a corresponding size.

    Details

  • Vibrate

    This plug-in makes any element you want "vibrate" every now and then. Can be used in conjunction with blink for maximum annoyance!

    Details

More Plug-ins

Recent Comments

  1. Private Krankenversicherung on "Phu Quoc, Sihanouk Ville, Koh Chang, Koh Wai & Koh Mak"

    the precious ideas u presented do help our team's ...

  2. jessasg on "Kiefer's Inability to Emphasize"

    знакомства жуковский рамен...

  3. Noeru_no_uta on "Phu Quoc, Sihanouk Ville, Koh Chang, Koh Wai & Koh Mak"

    I would like to exchange links with your site andr...

Page cached. Loaded in: 0.007 second(s).
Last DB change: 2010-08-31 14:33:29
Last file change: 2010-08-12 15:31:16
Cache created: 2010-09-03 06:16:48