我有一个带有几个缩略图的旋转木马,当用户点击其中一个时,它的假设是从左侧淡出一个较大的图像,然后从左侧淡入新图像。我相信我的语法是正确的,它像预期的那样淡入淡出,但不是我想要的那样向左。下面是单击事件的jQuery。
// click event handler for the <a> elements
$("#image_list a").click(function(evt) {
var lgURL = $(this).attr("href");
$("#image").animate({ opacity: 0, left: -205 }, 1000,
function () {
$("#image").attr("src", lgURL);
$(this).animate({ opacity: 1, left: "+=205" }, 1000)
}
); //end animate
evt.preventDefault();
}); //end click
发布于 2013-06-06 20:43:43
尝试使用左边的数字值而不是字符串。
既然你想加205,为什么不把左边设为0呢?
$(this).animate({ opacity: 1, left: 0 }, 1000)
发布于 2013-06-07 12:29:54
效果没有发生的原因是我没有指定相对于元素的位置。在我更新我的CSS后,它的动画效果在左边淡出,然后从左边回来,效果很不错。
#image {
position: relative;
height: 250px;
margin-bottom: 1em;
margin-left: 105px;
}
https://stackoverflow.com/questions/16971776
复制