如果用户将鼠标悬停在 div 上,Jquery 停止 SlideUp
如果用户仍将鼠标悬停在 SlideDown div 上,我试图停止 SlideUp 效果。 SlideDown div 是“utility-nav1”
对我当前代码的任何帮助或提示表示感谢:
var $j = jQuery.noConflict();
$j(document).ready(function() {
//show cart slide on hover
$j("#u1_cart").mouseenter(function() {
$j(this).addClass("open");
$j("#utility-nav1").slideDown();
$j("#slide-cart").load("cart_load.php", function() {
$j("#utility-nav1-loading").hide()
});
});
//hide cart slide on exit
$j("#u1_cart").mouseleave(function() {
$j("#utility-nav1").slideUp("slow", function() {
$j('#u1_cart').removeClass("open")
});
});
});
I am trying to stop a slideUp effect if the user is still hovering over the slideDown div. The slideDown div is "utility-nav1"
Any help or tips appreciated on my current code below:
var $j = jQuery.noConflict();
$j(document).ready(function() {
//show cart slide on hover
$j("#u1_cart").mouseenter(function() {
$j(this).addClass("open");
$j("#utility-nav1").slideDown();
$j("#slide-cart").load("cart_load.php", function() {
$j("#utility-nav1-loading").hide()
});
});
//hide cart slide on exit
$j("#u1_cart").mouseleave(function() {
$j("#utility-nav1").slideUp("slow", function() {
$j('#u1_cart').removeClass("open")
});
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有看到您的 HTML 和CSS,我不能 100% 确定这个问题,但我认为有两个地方可能会遇到麻烦:
.slideDown
、.slideUp
、和.slideToggle
需要在动画开始或结束时为元素赋予display:none
属性。因此,如果您尝试中断动画,后续的.slide
调用将无法正常工作。 这是此问题的示例。.stop()
。这将停止前一个。基于以上两点,我建议您放弃元素上的
display:none
属性,而不是调用.slide
方法,只需对高度进行动画处理。这是一个工作示例。
和代码:
Without seeing your HTML & CSS, I can't be 100% sure of the issue, but I think there are two likely places where you're running into trouble:
.slideDown
,.slideUp
, and.slideToggle
require adisplay:none
property to be given to the element either at the beginning or end of the animation. Therefore, if you try interrupting the animation, subsequent.slide
calls will not work correctly. Here's an example of this issue..stop()
on the element prior to calling the next animation. This will stop the previous one.Based on the two points above, I'd advise you to forgo the
display:none
property on the element, and rather than calling a.slide
method, simply animate the height.Here's a working example.
And the code:
我建议使用 hoverIntent 它可以为您完成大部分艰苦的工作。
这使用了 Jacob Nielson 推荐的方法,因为它可以防止用户在将光标移过购物车时意外打开购物车。
这未经测试但应该可以
编辑:
好的,根据您的标记,这是我在不改变很多东西的情况下能做的最好的事情。
这是 JS Bin 的链接
I would suggest using hoverIntent which does most of the hard work for you.
This uses the approach that Jacob Nielson recommends as it prevents users opening the cart by accident if they are moving their cursor past it.
This is untested but should work
EDIT:
Ok based on your markup, this is the best I can do without changing lots of things.
Here is a link to the JS Bin