2010-01-04 75 views
1

这里是我的地盘:的jQuery/CSS不选择,和stop()问题

http://www.raceramps.com/v2

将鼠标移到菜单上的右侧。请注意汽车服务,拖车拖拽和显示默认情况下完全放大。这是因为他们销售的产品较高,大多数浏览本网站的人都在寻找这些产品。

目前存在使用下面的代码手风琴菜单设置:

$(function(){ 
    $('.buttonEffectWrapper').hover (
     function() { 

      var effect = $(this).siblings().filter(":last"); 
      effect.stop().animate ({ opacity: 1}, { duration: 300 }); 

      $(this).stop().parent().animate({height: "110px"}, {duration: 300 });//accordion effect here 


     }, 
     function() { 
        var effect = $(this).siblings().filter(":last"); 
        effect.stop().animate ({ opacity: 0}, { duration: 300 }); 

        $(this).stop().parent().animate({height: "30px"}, {duration: 300 });//accordion effect here 

     } 
    ); 
}); 

首先,如果你在按钮上几次的一个水平移动鼠标,它建立了一个队列。我认为使用stop()应该可以解决这个问题,但它似乎不是。其次,我不希望前三个div(#car-service,#trailer-hauling和#display-and-show)在鼠标离开时折叠。我尝试了以下,但它选择一切其他。

$(this + ":not(#car-service, #trailer-hauling, #display-and-show)").stop().parent().animate({height: "30px"}, {duration: 300 }); 

;第三,如果你将鼠标放置一个DIV,然后移动到一个它下面,作为一个DIV扩大和其他倒塌,你的鼠标,你不会打算的位置结束。我能想到解决这个问题的唯一方法是不允许以前的div崩溃。

所以,如果我溺爱#car-service,然后去#trailer-hauling,#car-service不应该崩溃。但如果我从#trailer-hauling移动到#show-and-display,那么我想要#car-service收缩。这应该防止界面被破坏。

回答

0
if(!$(this).is("#car-service, #trailer-hauling, #display-and-show")){ 
    $(this).parent().animate({height: "30px"}, {duration: 300, queue:false}); 
} 

$(this)引用DOM中的单个元素(或元素组)。我认为最好是测试它是/是否有特定属性或过滤它,而不是使用$(this)选择器。

+0

代码不为我工作.. – Jared 2010-01-04 20:34:53

+0

@Jared,搞砸了动画功能。还采取了@戴维的队列问题的建议。现在已经修复了。它为你做了什么? – munch 2010-01-04 20:47:13

+0

我看到......它的地址(this),而它实际上需要看父母的div。如果(!$ this).parent()。是有效的。 – Jared 2010-01-04 20:51:29

0

第一animate()秒选项参数 ,您可以指定队列:

effect.animate({ 
    opacity: 1 
},{ 
    duration: 300, 
    queue: false 
}); 

第二 试试这个:

$(this).filter(function() { 
    return !this.id.match(/^(car-service||trailer-hauling||display-and-show)$/); 
}).someMethod()... 
+0

谢谢!第一次工作,但第二次,所以他们都没有崩溃... – Jared 2010-01-04 20:33:36

+0

@Jared:对不起,regExp中的一个小错误。固定。 – David 2010-01-04 20:47:23

+0

谢谢你的帮助! – Jared 2010-01-04 20:53:29