我试图使在悬停的元素摇不使用jQuery UI和所遇到下面的代码,但是我似乎无法弄清楚如何在悬停触发,该代码具有随机效应和它的每一个我尝试的时间让我困惑漫它。 我试图让他们在同一时间并非完全动画一个
http://jsfiddle.net/g6AeL/
$(function() {
var interval = 10;
var duration= 1000;
var shake= 3;
var vibrateIndex = 0;
var selector = $('aside.featured a'); /* Your own container ID*/
$(selector).click( /* The button ID */
function(){
vibrateIndex = setInterval(vibrate, interval);
setTimeout(stopVibration, duration);
});
var vibrate = function(){
$(selector).stop(true,false)
.css({position: 'relative',
left: Math.round(Math.random() * shake) - ((shake + 1) / 2) +'px',
top: Math.round(Math.random() * shake) - ((shake + 1) / 2) +'px'
});
}
var stopVibration = function() {
clearInterval(vibrateIndex);
$(selector).stop(true,false)
.css({position: 'static', left: '0px', top: '0px'});
};
});