我有一个 jquery 函数的问题,这里的代码:
$(".productUlContainer li.item_thumb").click(function(event){
event.preventDefault();
var actual = this;
//find the 5th element
thisLi = $(this).index() + 1;
thisLink = $(this).find(".bridalLink");
nLi = parseInt(thisLi/5 + 1);
nLi*=5;
$(".productUlContainer li:nth-child(5n)").html("");
$(".productUlContainer li:nth-child("+nLi+")").html( $("#html-results > div").html() );
//Data set
var thisLinkTitle = thisLink.attr("title");
var thisLinkPrice = thisLink.find(".item_price").data("price");
var thisLinkImgPath = thisLink.find(".promo").attr("src");
//Manage open/close effect
if ( previous != actual )
{
$(".productUlContainer li:nth-child("+nLi+")").hide(3000, function(){
/* Fill big box with clicked product details... */
$(".productUlContainer li:nth-child("+nLi+")").find($(".itemName")).text( thisLinkTitle );
$(".productUlContainer li:nth-child("+nLi+")").find($(".price")).text( thisLinkPrice );
$(".productUlContainer li:nth-child("+nLi+")").find($(".imgCollectionBridal")).attr("src", thisLinkImgPath );
$(".productUlContainer li:nth-child("+nLi+")").show(3000, function(){
previous=actual;
});
});
}
else
{
$(".productUlContainer li:nth-child("+nLi+")").hide(3000, function(){
previous=false;
});
}
});
部分代码结构非常复杂,不是我做的,最终结果应该是一个显示放大图像的div和点击缩略图的信息。如您所见,该函数试图隐藏一个最终已经打开的 div,并且在它应该使用新单击的缩略图更改其内容之后。
在我看来,将这 3 行放在 hide() 的回调函数中应该只有在隐藏序列完成后才能更改内容,但事实并非如此。在运行时,单击将开始隐藏序列,但内容更改会立即开始,而不是在隐藏完成后...
你能告诉我为什么吗?谢谢