【发布时间】:2018-03-21 15:44:13
【问题描述】:
我遇到了与this thread 中的问题类似的问题。然而,与我的不同之处在于我在 CSS 中设置了宽度。在我的代码中,有两个 div 依次使用slideDown() 以创建平滑的过渡效果。第一个 div tail 完全按预期工作,但在第二个 head 上,它只是突然出现,无论我什么时候添加它。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('.tail').hide();
$('.head').hide()
$("#button265764").click(function() {
$(".tail").slideUp().delay(0).slideDown(2000, "swing");
$(".head").slideUp().delay(2000).slideDown(1000, "swing");
$('#button265764').unbind('click');
});
});
</script>
<style>
<!-- not used in this transition) -->
.h_tail {
position: relative;
margin-top: 10px;
height: 10px;
width: 100px;
background-color: #73aae7;
margin-left: 5px;
transform: translateX(75px);
}
.tail {
position: relative;
width: 10px;
height: 50px;
background-color: #73aae7;
margin-left: 5px;
}
.head {
position: relative;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid #73aae7;
margin-left: 0;
}
</style>
<!--Stand-in, actual button is elsewhere-->
<div id="button265764">click me
</div>
<div class="tail">
</div>
<div class="head">
</div>
我认为这可能是由于头部的宽度为 0,但如果我将其更改为 10px 之类的东西只是为了测试,它仍然只是突然出现而没有 slideDown 效果。头部动作的延迟效果很好,所以这不仅仅是整个代码行没有运行的问题。
编辑:一些可能有帮助的附加信息:
我认为我可以明确排除 slideDown 方法按顺序排列的问题。我添加了第二个tail div(我称之为tail2),效果也很好。这个问题肯定与head div 有关。
该代码供参考:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.tail').hide();
$('.tail2').hide();
$('.head').hide()
$("#button265764").click(function(){
$(".tail").slideUp().delay(0).slideDown(2000, "swing");
$(".tail2").slideUp().delay(2000).slideDown(2000, "swing");
$(".head").slideUp().delay(4000).slideDown(1000, "swing");
$('#button265764').unbind("click");
});
});
</script>
<style>
.h_tail {
position: relative;
margin-top: 10px;
height: 10px;
width: 100px;
background-color: #73aae7;
margin-left: 5px;
transform: translateX(75px);
}
.tail {
position: relative;
width: 10px;
height: 50px;
background-color: #73aae7;
margin-left: 5px;
}
.tail2 {
position: relative;
width: 10px;
height: 50px;
background-color: #73aae7;
margin-left: 5px;
}
.head {
position: relative;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid #73aae7;
margin-left: 0;
}
</style>
<div id="button265764">click me
</div>
<div class="tail">
</div>
<div class="tail2">
</div>
<div class="head">
</div>
【问题讨论】:
-
您是否尝试过 slideDown - 缓慢、线性和快速以实现平滑过渡,如摇摆一样” - 在开始/结束时移动速度较慢,但在中间速度较快
-
我已经尝试了所有这些,也没有设置任何东西,结果都是一样的。
标签: javascript jquery html css