我需要在不指定时间间隔的情况下使用 jquery 在鼠标悬停中停止多个图像在圆圈中的旋转。我尝试了两种方式。
1. stops the one image using the div id in hover.
$(document).ready(function() {
$('#friends2').hover(function() {
$(this).stop();
}, function() {
moveit();
});
2. created a common class id 'a' for images and the stops in hover.
$(document).ready(function() {
$('.a').hover(function() {
$(this).stop();
}, function() {
moveit();
});
my script as
<script type="text/javascript">
var p = 0;
function moveit() {
p += .01;
var r = 165;
var xcenter = 550;
var ycenter = 300;
var newLeft = Math.floor(xcenter + (r* Math.cos(p+90)));
var newTop = Math.floor(ycenter + (r * Math.sin(p+90)));
var newLeft1 = Math.floor(xcenter + -(r* Math.cos(p+120)));
var newTop1 = Math.floor(ycenter + -(r * Math.sin(p+120)));
var newLeft2 = Math.floor(xcenter + (r* Math.cos(p+390)));
var newTop2 = Math.floor(ycenter + (r * Math.sin(p+390)));
$('#friends').animate({
top: newTop,
left: newLeft,
}, 10, function() {
moveit();
});
$('#friends2').animate({
top: newTop1,
left: newLeft1,
},10, function() {
moveit();
});
$('#friends3').animate({
top: newTop2,
left: newLeft2,
},10, function() {
moveit();
});
}
问题是悬停不适用于所有图像..还有其他方法..建议吗?