0

如您所见,我是 jquery 的新手,我正在尝试做一个简单的效果,您可以在其中过滤带有菜单链接的画廊,我希望在悬停时更改不透明度,在单击时我需要悬停以停止工作。我尝试的是在单击时添加一个“.disabled”类,它确实添加到我的菜单链接中,并将悬停功能设置为 a.not(."disabled")但显然在 dom 准备好后悬停不检查类,我该如何解决这个问题?有关如何优化此功能的任何其他指针都会有所帮助。提前致谢。克拉齐德

这是我的代码:

$('#menu-item-43 a ,#menu-item-44 a, #menu-item-42 a, #menu-item-64 a').click(function() {
                $('#menu-item-43 a ,#menu-item-44 a, #menu-item-42 a, #menu-item-64 a').addClass('disabled');
            });


            $('#menu-item-42 a').click(function() {
                $('.exhibition, .prototyping').stop().animate({ opacity: 0.0 }, 500);
            });
            $('#menu-item-42 a').click(function() {
                $('.design').stop().animate({ opacity: 1.0 }, 500);
            });

            $('#menu-item-43 a').click(function() {
                $('.design, .prototyping').stop().animate({ opacity: 0.0 }, 500);
            });
            $('#menu-item-43 a').click(function() {
                $('.exhibition').stop().animate({ opacity: 1.0 }, 500);
            });

            $('#menu-item-44 a').click(function() {
                $('.design, .exhibition').stop().animate({ opacity: 0.0 }, 500);
            });
            $('#menu-item-44 a').click(function() {
                $('.prototyping').stop().animate({ opacity: 1.0 }, 500);
            });

            $('#menu-item-64 a').click(function() {
                $('.design, .exhibition, .prototyping').stop().animate({ opacity: 1.0 }, 500);
            });  



            $('#menu-item-42 a').not('.disabled').hover(function() {
                $('.exhibition, .prototyping').stop().animate({ opacity: 0.0 }, 500);
            });
            $('#menu-item-42 a').not('.disabled').hover(function() {
                $('.design').stop().animate({ opacity: 1.0 }, 500);
            });

            $('#menu-item-43 a').not('.disabled').hover(function() {
                $('.design, .prototyping').stop().animate({ opacity: 0.0 }, 500);
            });
            $('#menu-item-43 a').not('.disabled').hover(function() {
                $('.exhibition').stop().animate({ opacity: 1.0 }, 500);
            });

            $('#menu-item-44 a').not('.disabled').hover(function() {
                $('.design, .exhibition').stop().animate({ opacity: 0.0 }, 500);
            });
            $('#menu-item-44 a').not('.disabled').hover(function() {
                $('.prototyping').stop().animate({ opacity: 1.0 }, 500);
            });

            $('#menu-item-64 a').not('.disabled').hover(function() {
                $('.design, .exhibition, .prototyping').stop().animate({ opacity: 1.0 }, 500);
            });  
4

1 回答 1

0

我认为你应该这样做

$('#menu-item-43 a').hover(function() {
   if (!$(this).hasClass('disabled'))
      $('.exhibition').stop().animate({ opacity: 1.0 }, 500);
});
于 2012-07-23T02:03:36.547 回答