我设法将一块代码在基于某些条件的容器div内动画一个div - 但是我的数学必须略微偏离,因为它的动画稍微偏左。看例子@http://dev.whiteb0x.com/galleryjQuery的动画div左/右如果条件
var width = $('#nav').width();
$('#nav').width(width * 2 + 20);
$(".nav-next").click(function() {
var pos = $('#nav').position();
var width = $('#nav-viewport').width();
var width = width * (-1);
alert(width);
if (pos.left <= 0 && pos.left > width && !$('#nav').is(':animated')) {
$('#nav li:first').before($('#nav li:last'));
$("#nav").animate({"left": "-=300"}, "slow");
}
});
$(".nav-prev").click(function() {
var pos = $('#nav').position();
if (!pos.left <= 0 && !$('#nav').is(':animated')) {
$('#nav li:first').before($('#nav li:last'));
$("#nav").animate({"left": "+=300"}, "slow");
}
});
您声明在内部范围'width'两次。然而,不是你的问题的根源。 – 2012-04-24 21:28:13
此外,动画在Firefox中似乎不起作用。我不确定是什么原因造成的。 – 2012-04-24 21:33:54
啊,可能是因为你在你的实时页面上定义了“left”和“right”css。无论您滚动的方向如何,您都需要始终使用一种或另一种。混合和匹配只会造成麻烦。 – 2012-04-24 21:38:11