javascript - 悬停时的 jQuery 动画延迟

标签 javascript jquery html css animation

我正在编写一些 jQuery 代码来为所有 .linkbox 设置动画以增加高度并且它工作得很好除了我点击的元素比其他两个元素慢(所以它就像悬停时更慢),我如何使所有三个元素以完全相同的方式进行动画处理,他们不应该已经这样做了吗?他们也从底部开始动画,是否可以告诉它从顶部开始动画?

这是所有代码的链接:http://jsbin.com/fihes/2/edit?html,css,js,output

提前致谢!

html:

<body>
    <div class="linkbox"><div class="text">Om mig</div></div>
    <div class="linkbox"><div class="text">Portfolio</div></div>
    <div class="linkbox"><div class="text">Kontakt</div></div>
</body>

CSS:

body{
background:black;
background-attachment:fixed;
width: 102%;
margin: 0px;
padding: 0px;
}

.linkbox{
opacity: 0.5;
width:33%;
height: 200px;
background-color: #ffffff;
padding: 0px;
margin: -2px;
display:inline-block;
margin-top: 35%;    
}

.linkbox:hover{
    opacity: 1;
    transition: all 0.4s ease;

}

.text{
    text-align:center;
    font-family: Helvetica;
    font-size: 42px;
    padding: 74px;
}

jQuery:

$(document).ready(function(){
$('.linkbox').click(function(){
    $('.linkbox').animate({height:"400px"}, "slow", "swing");
});
$('.text').click(function(){
    $('.text').fadeTo("fast", 0);
});
});

最佳答案

您的点击代码较慢,因为您有 "slow" ,您可以将其更改为 "fast" ,如下所示:

$('.linkbox').click(function(){
    $('.linkbox').animate({height:"400px"}, "fast", "swing");
});

要回答您的第二个问题,我认为仅使用 .animate() 是不可能让它从上向下滑动的。但是,有 .slideDown() 效果。

The .slideDown() method animates the height of the matched elements. This causes lower parts of the page to slide down, making way for the revealed items

http://api.jquery.com/slidedown/

关于javascript - 悬停时的 jQuery 动画延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21798929/

相关文章:

jquery - 在 Jquery dynatree 中展开 Lazyload 上的所有节点

javascript - 在外部设置显示样式会导致 onclick() 事件两次单击以初始化

asp.net - HTML 标记中 gridview 中 BoundField 的自定义消息

javascript - ES6 做 for of get prototype values - 如何检查 hasownproperty

javascript - 相对于当前 Div 的边距

javascript - 监控 chrome 中的自定义事件?

javascript - 使用 Url 中的哈希值重新加载页面 (F5)

JavaScript 从字段中查找值

javascript - 使用 ScrollTo 在 jQuery slimScroll 中滚动条不移动

javascript - 制作视频比较 slider 全宽/高度