fadeIn 在 fadeOut 的回调中调用,在某些项目上闪烁或出现两次?
我正在使用 select
表单元素来显示时间表的不同日期。由于某种原因,第三天和第四天在选择时闪烁,我不知道为什么。而如果选择了第三天或第四天,则会导致其他天在选择时闪烁。
此处提供示例: http://jsfiddle.net/waffl/WBHQc/1/
HTML:
<select id="date-select" name="date">
<option value="day1" selected="selected">Thursday</option>
<option value="day2">Friday</option>
<option value="day3">Saturday</option>
<option value="day4">Sunday</option>
</select>
<div id="schedule">
<div id="day1"><img src="http://placehold.it/350x150"></div>
<div id="day2"><img src="http://placehold.it/350x150/ff00000"></div>
<div id="day3"><img src="http://placehold.it/350x150/37FDFC"></div>
<div id="day4"><img src="http://placehold.it/350x150/FFC125"></div>
</div>
CSS:
#day2, #day3, #day4 {
display: none;
}
JS:
$('#date-select').change(function() {
var newDay = $(this).val();
$("#schedule > div").fadeOut(200,function() {
$("#schedule #"+newDay).fadeIn();
});
});
I am using a select
form element to show different days for a schedule. For some reason, the third and fourth days are blinking when chosen and I'm not sure why. And if the third or fourth days are selected, it causes other days to blink when chosen.
Example available here:
http://jsfiddle.net/waffl/WBHQc/1/
HTML:
<select id="date-select" name="date">
<option value="day1" selected="selected">Thursday</option>
<option value="day2">Friday</option>
<option value="day3">Saturday</option>
<option value="day4">Sunday</option>
</select>
<div id="schedule">
<div id="day1"><img src="http://placehold.it/350x150"></div>
<div id="day2"><img src="http://placehold.it/350x150/ff00000"></div>
<div id="day3"><img src="http://placehold.it/350x150/37FDFC"></div>
<div id="day4"><img src="http://placehold.it/350x150/FFC125"></div>
</div>
CSS:
#day2, #day3, #day4 {
display: none;
}
JS:
$('#date-select').change(function() {
var newDay = $(this).val();
$("#schedule > div").fadeOut(200,function() {
$("#schedule #"+newDay).fadeIn();
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎是一个与时间相关的问题。使用
#schedule> div
作为选择器会导致所有 div 开始淡出,然后每个 div 都会触发 div 的fadeIn
。 而不是全部):对于最简单的解决方案,我可能只是缓存当前选定的 div,然后使用它淡出(仅淡出一个 net/dbrecht/HVsFu/" rel="nofollow">在这里摆弄
Seems to be a timing related issue. Using
#schedule > div
as your selector causes all divs to start fading out, and then each triggering thefadeIn
of the div. For the most straightforward solution, I'd probably just cache off the currently selected div and then use that to fade out (only fade out one rather than all of them):Fiddle here
检查工作示例 http://jsfiddle.net/MNXvK/1/
Check working example at http://jsfiddle.net/MNXvK/1/