Vibrate 2.0

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

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

Post a Comment

blog comments powered by Disqus

Random jQuery Plug-ins

  • Image Zoom

    This plug-in makes links pointing to images open in the "Image Zoom". Clicking a link will zoom out the clicked image to its target-image. Click anywh...

    Details

  • View More

    This plug-in allows an element's contents to be hidden untill the user clicks a certain element. It works exactly like the HTML5 details and summary e...

    Details

  • Code Block Toolbar

    If you post code-examples on your site you can use this plug-in to add some nifty buttons below each code-example that allows the user to, for example...

    Details

More Plug-ins

Recent Comments

Powered by Disqus