[英]Controlling the speed of a jquery animation
I've been getting help with building this function from the community here, which I'm very thankful for - js newb. 我一直在这里的社区中获得构建此功能的帮助,对此我非常感激-js newb。 But there's something that I can't seem to figure out.
但是有些事情我似乎无法弄清楚。
I have a relatively positioned div that slides into view when a trigger is hovered over. 我有一个相对定位的div,当将鼠标悬停在上面时,它会滑入视图。 It subsequently pushes the content below said div down - perfect.
随后,它会将上述div下面的内容下推-完美。 The problem is I can't figure out how to control the speed of the div that being slid in. I can control other things, like say the speed of the opacity of the content in said div, but not how quickly that div appears.
问题是我无法弄清楚如何控制插入的div的速度。我可以控制其他事情,例如说该div中内容的不透明度的速度,但不能控制该div出现的速度。
If someone can be kind enough to explain how I can affect the speed of slide effect it would be greatly appreciated, as always. 如果有人能够友好地解释我如何影响幻灯片效果的速度,那么一如既往,将不胜感激。
Here's my markup: 这是我的标记:
<nav class="site-navigation" role="navigation">
<div class="menu-1-container">
<ul id="menu-1" class="menu">
<li id="menu-item-1"> <a href="#">Releases</a>
</li>
</ul>
</div>
</nav>
<div class="dropdown-contain">
<p>Content</p>
</div>
<div class="other">
<p>Other Content</p>
</div>
Here's some CSS: 这是一些CSS:
.site-navigation {
background: #ccc;
padding: 25px 0;
}
.other {
background: #ccc;
padding: 25px;
}
.dropdown-contain {
display: none;
opacity: 0;
position: relative;
width: 100%;
z-index: 1;
height: 100px;
}
And here's the jQuery: 这是jQuery:
$(function () {
$(document).on("mouseover", "#menu-item-1, .dropdown-contain", function () {
$(".dropdown-contain").css({
"display": "block"
});
$(".dropdown-contain").stop().animate({
opacity: 1
}, 1000);
});
$(document).on("mouseleave", "#menu-item-1, .dropdown-contain", function () {
$(".dropdown-contain").stop().animate({
opacity: 0
}, 1000, function () {
$(".dropdown-contain").css({
"display": "none"
});
});
});
});
thanks! 谢谢!
Something like slideToggle
will slide the content area down, and then fade in the text. 诸如
slideToggle
类的slideToggle
将使内容区域向下滑动,然后淡入文本。
$(function () {
$(document).on("mouseenter", "#menu-item-1, .dropdown-contain", function () {
$(".dropdown-contain").slideToggle(500, function() {
$(this).fadeTo(500, 1);
});
});
$(document).on("mouseleave", "#menu-item-1, .dropdown-contain", function () {
$(".dropdown-contain").fadeTo(500, 0, function() {
$(this).slideToggle(500);
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.