【问题标题】:How to insert css rule into javascript?如何将css规则插入javascript?
【发布时间】:2013-08-01 18:53:00
【问题描述】:
animation: scaleUp 0.3s linear 0.4s forwards;

animation: scaleDown 0.3s linear forwards;

您好,我在过滤内容时尝试为内容设置动画。 当'隐藏所有不共享我们的类的元素'和'显示所有共享ourClass的元素'但我真的不知道如何打开和关闭标签,因为我对 Javascript 不太了解。如果你能帮助我,我将不胜感激。谢谢。

$(document).ready(function() {
$('#filterOptions li a').click(function() {
    // fetch the class of the clicked item
    var ourClass = $(this).attr('class');

    // reset the active class on all the buttons
    $('#filterOptions li').removeClass('active');
    // update the active state on our clicked button
    $(this).parent().addClass('active');

    if(ourClass == 'all') {
        // show all our items
        $('#ourHolder').children('div.item').show();    
    }
    else {
        // hide all elements that don't share ourClass
        $('#ourHolder').children('div:not(.' + ourClass + ')').hide();

        // show all elements that do share ourClass
        $('#ourHolder').children('div.' + ourClass).show();
    }
    return false;
});

});

【问题讨论】:

  • 使用你想添加的规则的类

标签: javascript css sorting animation filtering


【解决方案1】:

除非我遗漏了什么,否则我看不出以下内容不起作用的原因:

$("#ourHolder").css("animation","scaleUp 0.3s linear 0.4s forwards");

$("#ourHolder").css({"animation" : "scaleUp 0.3s linear 0.4s forwards"});

不过,将 css 添加到类并切换类,这绝对是一种更好的做法。

请注意,我不确定您想要什么选择器,我只是选择了#ourHolder 作为示例。

【讨论】:

  • 您好,非常感谢您的快速回复,但不幸的是它不起作用。但是,我正在使用这个网站上的这个简单的过滤方法。evoluted.net/thinktank/web-development/jquery-filtering 我只是想知道有什么方法可以只使用 css 来为内容制作动画。谢谢。
  • @Kim:你能告诉我们你尝试了什么吗?一个 jsFiddle 会很棒。
  • jsfiddle.net/ejkim2000/J7TF4 这是我尝试过的,但动画不起作用。我正在尝试尽可能简单地使用过滤系统,并尝试仅使用 css 为内容设置动画。谢谢。
猜你喜欢
  • 2013-01-24
  • 2016-12-28
  • 2012-09-28
  • 1970-01-01
  • 2015-07-07
  • 2010-11-27
相关资源
最近更新 更多