带有slideUp/Down和clearQueue的jQuery问题
jQuery issue with slideUp/Down and clearQueue
当使用jquery将鼠标悬停在元素上时,我有一个显示和隐藏的下拉菜单(slideUp和slideDown)。。。
$("#element").hover( function() {
$(this).next().clearQueue();
$(this).next().slideDown(); //animate({height:300},100);
}, function() {
if (!$(this).next().is(':hover')) {
$(this).next().clearQueue();
$(this).next().slideUp(); //animate({height:0},100);
}
});
我最初没有包含clearQueues()这一行,但如果用户不稳定地在#元素上方和外部悬停,这会导致slideUp/Down排队并动画化很长一段时间。
添加该行意味着,如果用户快速悬停并退出,则下拉列表不会完全显示。
我可以通过设置幻灯片向下的动画来解决这个问题,但问题是我不知道需要设置动画的确切高度,因为它可能会改变。
有没有办法阻止这种行为?
我在使用slideUp和slideDown时遇到了类似的问题,其中slideDown会在动画过程中为元素提供静态高度,而元素必须保持动态大小,因为它的内容随时可能更改。我通过在animationFinished回调中将CSS高度值设置为空字符串(即")来修复此问题。
所以这应该能解决你的问题:
$("#element").hover(function () {
$(this).next().stop(true).slideDown(400, function () { // .stop(true) is basically the same as .clearQueue() except that it only stops and clears animations
$(this).css('height', '');
}); //animate({height:300},100);
}, function () {
if (!$(this).next().is(':hover')) {
$(this).next().stop(true).slideUp(); //animate({height:0},100);
}
});
相关文章:
- 带有slideUp/Down和clearQueue的jQuery问题
- html代码没有运行jquery问题
- 使用jquery问题将文本附加到文本区域
- 当变量中的.find()项有多个匹配项时,jQuery问题
- 由于jQuery问题,在实现Disqus插件时出现问题
- 在jquery问题中设置值
- 基本有类 jquery 问题
- 使用最接近查找文本输入的JQuery问题
- css上的Jquery问题
- 使用 jQuery 问题验证和提交表单
- 循环每个 jQuery 问题
- insertBefore() 一个 iframe jquery 问题
- Magento - 原型.js和jQuery问题 - 添加到购物车按钮
- 谷歌浏览器jQuery问题
- IE 中止插件脚本会导致现场出现 JQuery 问题
- 在 jquery 问题中加载更多选项
- Javascript - 使用 jQuery 问题选择选项
- 使用两个函数时出现 Jquery 问题
- jquery问题 - 它不会相应地改变它
- Jquery问题在Firefox和IE中,但不是Chrome