The reason it constantly shakes is because the plugin is set up to create an element that swings unsteadily ... forever. Shaking is done using setInterval . setInterval is also used to trigger intermittent shaking periods.
Andreas Lagerkvist, , , setInterval() doVibration(). , , ( , , - ... ? )
, div, . hover(). , , , div.
$('#jquery-vibrate-example').hover(function() {$(this).vibrate();});
, , . mouseenter()
$('#jquery-vibrate-example').mouseenter(function() {$(this).vibrate();});
.vibrate(), , ( ) : , $(this).vibrate({"speed":100,"duration":800,"spread":5});. speed, , speed setInterval() . :
jQuery.fn.vibrate = function (conf) {
var config = jQuery.extend({
speed: 30,
duration: 1000,
spread: 3
}, conf);
return this.each(function () {
var t = 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)'
});
};
var doVibration = function () {
var vibrationInterval = setInterval(vibrate, config.speed);
var stopVibration = function () {
clearInterval(vibrationInterval);
t.css({
position: 'static',
WebkitTransform: 'rotate(0deg)'
});
};
setTimeout(stopVibration, config.duration);
};
doVibration();
});
};
. relative..., , absolute ly.