我目前正在为一个老派的c64群组做一个网站,我想展示一下像旧介绍中那样左右摆动的logo会很好。
我以为我有,但它摆动了一个方向,然后回来,然后停止。
代码如下:
jQuery(document).ready(function() {
function right() {
$('header img').animate({
left: '680px',
}, 5000, function() {
left()
});
}
function left() {
$('header img').animate({
left: '0px',
}, 5000, function() {
right()
});
}
});我确信我错过了一些简单的东西,任何帮助都将不胜感激。
发布于 2012-04-26 21:23:05
看起来这可能是范围的问题。尝试在就绪事件处理程序外部定义函数,如下所示:
function right() {
$('header img').animate({
left: '680px',
}, 5000, function() {
left();
});
}
function left() {
$('header img').animate({
left: '0px',
}, 5000, function() {
right();
});
}
jQuery(document).ready(function() {
right();
});发布于 2012-04-27 08:26:10
我以为这和动画队列有关。我将stop()添加到t动画中,现在它可以工作了。因此,如果你想在你的页面上有一个摆动的徽标,下面是代码:
jQuery(document).ready(function() {
right();
function right() {
$('#images img').stop().animate({
// Move the image right to the width of the container, minus the width of the image
left: '480px',
}, 5000, function() {
left()
});
}
function left() {
$('#images img').stop().animate({
// Move back to the left
left: '0px',
}, 5000, function() {
right()
});
}
});https://stackoverflow.com/questions/10334191
复制相似问题