jQuery fadeIn() fadeOut() 计时问题
我的页面上有 6 个元素。每个元素旁边都会显示优先级编号。我试图在元素移动后更新这个数字。但是,我对 jQuery fadeIn() fadeOut() 方法的某些计时有疑问。我的目标是淡出一些文本,更新文本,然后淡入文本。第一种方法是做我需要的一切。不过,使用该方法有时文本会在 fadeOut() 完成之前发生变化并且看起来很糟糕。这就是为什么我尝试使用 fadeOut() 方法的函数,并使其更改文本并仅在 fadeOut() 完成时才执行 fadeIn() 。第二种方法的问题是每个元素都显示优先级“7”。我不知道为什么!有谁知道为什么第二种方法不能正常工作?
方法#1
var priorityNumber = 1;
$("#rotatorList ul li .priority-number").each(function(){
$(this).fadeOut(200).text(priorityNumber).fadeIn(200);
priorityNumber = priorityNumber+1;
});
方法#2
var priorityNumber = 1;
$("#rotatorList ul li .priority-number").each(function(){
$(this).fadeOut(200, function(){
$(this).text(priorityNumber).fadeIn(200);
});
priorityNumber = priorityNumber+1;
});
I have 6 elements on my page. A priority number is displayed next to each element. I am trying to update this number after an element gets moved. But, i am having an issue with some timing of the jQuery fadeIn() fadeOut() methods. My goal is to fade out some text, update the text, then fade the text back in. The first method is doing everything i need. Although, with that method sometimes the text will change before fadeOut() has completed and looks bad. This is why i was trying to use a function for the fadeOut() method and make it change the text and execute the fadeIn() only when the fadeOut() was complete. The problem with this second method is that every element is displaying a priority of "7". I don't know why! Does anyone know why the second method is not working correctly?
Method #1
var priorityNumber = 1;
$("#rotatorList ul li .priority-number").each(function(){
$(this).fadeOut(200).text(priorityNumber).fadeIn(200);
priorityNumber = priorityNumber+1;
});
Method #2
var priorityNumber = 1;
$("#rotatorList ul li .priority-number").each(function(){
$(this).fadeOut(200, function(){
$(this).text(priorityNumber).fadeIn(200);
});
priorityNumber = priorityNumber+1;
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你试过这样做吗?:
像这样 http://jsfiddle.net/JUSa7/1/ 小提琴(如果我误解了你,请告诉我)
你可以尝试的另一件事是使用每个提供的索引:
Have you tried doing this?:
like this http://jsfiddle.net/JUSa7/1/ fiddle (tell me if I missunderstood you)
Another thing you could try is using the index provided by each: