fadeIn仅在未显示且fadeOut完成时显示
fadeIn only if not shown and fadeOut complete
请检查Edit,因为它显示了我迄今为止取得的进展
我在调用jquery的fadeOut
完整函数时遇到问题。在调用fadeIn
之前,我希望内容完全转到fadeOut
如果已经显示了fadeOut
和fadeIn
各自的内容,我也不希望将内容发送给它们。例如,如果正在显示选项1的内容,并且您再次单击选项1,则它不应淡出并返回,应保持不变。
https://jsfiddle.net/jzhang172/6kpyhpbh/7/
$('.option1').click(function(){
$('.box').children().fadeOut(1000,function(){
$('.one').fadeIn();
});
});
$('.option2').click(function(){
$('.box').children().fadeOut(1000,function(){
$('.two').fadeIn();
});
});
$('.option3').click(function(){
$('.box').children().fadeOut(1000,function(){
$('.three').fadeIn();
});
});
.cheese{
height:200px;
width:300px;
background:blue;
}
.cheese div{
color:white;background:red;
}
.box{
height:300px;
width:500px;
}
.box .content{
display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="cheese">
<div class="option1">Option 1</div>
<div class="option2">Option 2</div>
<div class="option3">Option 3</div>
</div>
<div class="box">
<div class="content one">Content One</div>
<div class="content two">Content Two</div>
<div class="content three">Content Three</div>
</div>
第1版:我相信我已经解决了在淡出之前无法正常淡出的问题。我使用了promise()并完成了,但我需要这样做才能让它工作。。。Fiddle here:https://jsfiddle.net/jzhang172/6kpyhpbh/10/
第2版:所以,我有两个工作要求,但有一个问题。。。如果你连续快速点击两个选项,两个选项都显示内容,我只想显示最新的一个。https://jsfiddle.net/jzhang172/6kpyhpbh/16/
我使用了.not(":hidden")
函数来实现淡出功能,这样并不是每个子项都会淡出,从而导致显示问题。
$('.box').children().not(":hidden").fadeOut(1000,function(){
// code
});
此外,您需要在开头显示至少一个元素,这是我为索引0所做的。
$('.box').children().eq(0).show();
请参阅更新后的小提琴。
$('.option1').click(function(){
$('.box').children().hide(function(){
$('.one').show();
});
});
$('.option2').click(function(){
$('.box').children().hide(function(){
$('.two').show();
});
});
$('.option3').click(function(){
$('.box').children().hide(function(){
$('.three').show();
});
});
.cheese{
height:200px;
width:300px;
background:blue;
}
.cheese div{
color:white;background:red;
}
.box{
height:300px;
width:500px;
transition-duration:0s;
}
*{transition-duration:0s;}
.box .content{
display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="cheese">
<div class="option1">Option 1</div>
<div class="option2">Option 2</div>
<div class="option3">Option 3</div>
</div>
<div class="box">
<div class="content one">Content One</div>
<div class="content two">Content Two</div>
<div class="content three">Content Three</div>
</div>
在淡入或淡出前使用可见性检查:
If ($(.yourElement).is(":visible") )
{
//Do your fade out
}
您可以在动画期间禁用/启用元素
$(.yourElement).prop ('disabled', true);
$(.yourElement).fadeIn (1000, function () {
$(this).prop ('disabled', false);
});
或者使用承诺在该元素的所有动画之后执行动画
element.promise ().done ( function () {
//Do something on completion of all animations
});
如果你想让它触发,即使元素已经完成动画:
element.promise ().always ( function () {
//Do something on completion of all animations
});
您可以使用data-dir
html5新功能来访问不同的.content
类
Fiddle:https://jsfiddle.net/6kpyhpbh/17/
$('.box').children('div').hide();
$('.cheese div').on('click',function(){
var direction = $(this).data('dir')
if(direction === 'option1'){
$('.box').children('.contentOne').fadeIn().siblings('div').fadeOut();
}
if(direction === 'option2'){
$('.box').children('.contentTwo').fadeIn().siblings('div').fadeOut();
}
if(direction === 'option3'){
$('.box').children('.contentThree').fadeIn().siblings('div').fadeOut();
}
});
- 让文本输入幻灯片显示输入时的新文本输入?然后向后滑动
- 如何在自动完成时设置属性标题
- Adobe Edge:动画完成时添加onComplete处理程序
- 显示指令时调用指令方法
- 当一些事情可以通过JS或CSS完成时,我应该选择哪种方式
- 当send_data完成时,Rails send_data和Javascript处理程序
- 如何在uploadify/uploadifive中使用OnQueueComplete事件在队列完成时发送电子邮件
- 在操作完成时执行函数
- JQuery AJAX 在 GET 请求完成时返回 XML
- fadeIn仅在未显示且fadeOut完成时显示
- jQuery .load - 仅在所有函数完成时显示
- 在函数完成时显示加载动画
- 为什么不是't此图像显示在AJAX请求发送之前,并在完成时隐藏
- 在Javascript函数完成时显示HTML元素
- 多个IF语句在输入完成时显示图像
- 倒计时计时器需要显示秒,目前只是显示完成时
- Jquery ajax加载动画不应该在内容完成时显示(延迟)
- 如何在页面加载未完成时显示警告
- 如何在选择后在html页面上显示加载图像,直到查询完成,当请求完成时隐藏图像
- 如何让我的页面显示我的函数在完成时而不是在每个函数完成时处理的数据