Javascript 在div box周围轻微浮动
我想在我的网站上的三个div框稍微切换,慢慢地“悬停”,直到鼠标在它们上面——然后我的自定义悬停效果就会发生,我已经在使用了。(抖动/嘎嘎声和不透明)。但是我很难理解如何让动画继续 这就是我的小提琴——我错过了什么Javascript 在div box周围轻微浮动,javascript,jquery,css,Javascript,Jquery,Css,我想在我的网站上的三个div框稍微切换,慢慢地“悬停”,直到鼠标在它们上面——然后我的自定义悬停效果就会发生,我已经在使用了。(抖动/嘎嘎声和不透明)。但是我很难理解如何让动画继续 这就是我的小提琴——我错过了什么 未捕获引用错误:未定义持续时间 像这样改变: 未捕获引用错误:未定义持续时间 像这样改变: 您在示例中没有指定持续时间。至于使div缓慢浮动,您可以应用动画,使用随机的顶部和左侧值重复动画,如下所示: $(function() { var timeout; funct
未捕获引用错误:未定义持续时间 像这样改变:
未捕获引用错误:未定义持续时间 像这样改变:
您在示例中没有指定持续时间。至于使div缓慢浮动,您可以应用动画,使用随机的顶部和左侧值重复动画,如下所示:
$(function() {
var timeout;
function moveAimlessly() {
$(".aimless").each(function() {
$(this).stop().animate({
top: Math.floor(Math.random()*2) == 1 ? "+=" + Math.floor(Math.random()*41).toString() : "-=" + Math.floor(Math.random()*41).toString(),
left: Math.floor(Math.random()*2) == 1 ? "+=" + Math.floor(Math.random()*41).toString() : "-=" + Math.floor(Math.random()*41).toString()
}, 4000);
});
timeout = setTimeout(moveAimlessly, 4000);
}
moveAimlessly();
$(".aimless").on("hover", function() {
clearTimeout(timeout);
$(".aimless").stop();
});
});
链接到示例:您没有在示例中指定持续时间。至于使div缓慢浮动,您可以应用动画,使用随机的顶部和左侧值重复动画,如下所示:
$(function() {
var timeout;
function moveAimlessly() {
$(".aimless").each(function() {
$(this).stop().animate({
top: Math.floor(Math.random()*2) == 1 ? "+=" + Math.floor(Math.random()*41).toString() : "-=" + Math.floor(Math.random()*41).toString(),
left: Math.floor(Math.random()*2) == 1 ? "+=" + Math.floor(Math.random()*41).toString() : "-=" + Math.floor(Math.random()*41).toString()
}, 4000);
});
timeout = setTimeout(moveAimlessly, 4000);
}
moveAimlessly();
$(".aimless").on("hover", function() {
clearTimeout(timeout);
$(".aimless").stop();
});
});
链接到示例:这太棒了,但是有没有办法让div在悬停停止后继续浮动?@cam77当然,只要去掉
$(“.aimless”)中的代码即可。on(“hover”,function(){…
。这太棒了,但是有没有办法让div在悬停解除后继续浮动?@cam77当然,只要去掉$(“.aimless”)。on(“hover”,function(){…
。