【问题标题】:How to stop a jQuery effect on a menu item with the class of .curent?如何在.current 类的菜单项上停止 jQuery 效果?
【发布时间】:2012-02-21 16:55:42
【问题描述】:

我在页面右侧的边栏中有一个博客类别列表。

我已经设置了一个 jQuery 效果,这样当您将鼠标悬停在一个类别名称上时,它会在左侧填充 5px 进行动画处理。

一切正常,但如果您单击一个类别,我希望它带您进入具有相同类别侧边栏列表的类别页面,但当前类别的类为 .current。

我希望当前类别已经在左侧有 5px 填充,并且在悬停时没有效果。

基本上只是为了让它从列表中的其他类别中脱颖而出。

这是我有 atm 的 jQuery:

// blog categories animation
$(function() {
    $('#blog-categories ul li a').hover(
    function(){ $(this).find('img').animate({paddingLeft: '+=5'}, 100); },
    function(){ $(this).find('img').animate({paddingLeft: '-=5'}, 100); }
    );
});

如果有人知道在当前类别项目上已经存在 5px 添加填充的好方法。

即'#blog-categories ul li a.current'

悬停时没有更多动画,那太好了!

我希望我在这里解释清楚了:)


这是我想要的 .current 类别项目的屏幕截图:

【问题讨论】:

    标签: jquery function jquery-animate


    【解决方案1】:

    尝试使用.not() 方法

    $(function() {
        $('#blog-categories ul li a').hover(
        function(){ $(this).not('.current').find('img').animate({paddingLeft: '+=5'}, 100); },
        function(){ $(this).not('.current').find('img').animate({paddingLeft: '-=5'}, 100); }
        );
    });
    

    要拥有 5px 的内边距,为什么不简单地将其添加到 .current 类中?

    【讨论】:

    • 干杯我现在就试试这个,让你知道我的进展:)
    • 辛苦了!感谢您的快速回复:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-08
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多