它不断抖动的原因是插件被设置为创建一个间歇性抖动的元素。永远。奶昔是用
从工作
整个的
有人盘旋的时候…你…吗?那太烦人了)
把你想要振动的东西放在一个分区里,用
$('#jquery-vibrate-example').hover(function() {$(this).vibrate();});
$('#jquery-vibrate-example').mouseenter(function() {$(this).vibrate();});
当你打电话
.vibrate()
您可以将速度、持续时间和传播(我删除了频率)作为对象文字的一部分传入,以微调振动:
$(this).vibrate({"speed":100,"duration":800,"spread":5});
例如。更大的
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)' // cheers to erik@birdy.nu for the rotation-idea
});
};
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
定位元件。