jquery - 使用 jquery 改变不透明度的数据过滤器

标签 jquery css filtering

我正在构建一个包含可过滤元素的网站。我基本上想更改过滤类中元素的不透明度。所以 100% 的不透明度元素具有 'active' 类,其他所有不具有 'active' 类的元素的不透明度为 50%。单击每个元素应淡入或淡出。这是代码。我正在为这个而挠头……

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

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

    if(ourClass == 'all') {
      // show all our items
      $('#projects').children('li.two').show();
    }
    else {
      // 50% Opacity of all elements that don't share ourClass
      $('#projects').children('li:not(.' + ourClass + ')').fadeTo('slow', 0.5, function();
      // !00% Opacity of all elements that do share ourClass
      $('#projects').children('li.' + ourClass).fadeTo('slow', 1, function();
    }
    return false;
  });
});

最佳答案

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

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

if(ourClass == 'all') {
  // show all our items
  $('#projects').children('li.two').animate({opacity:1}, 400);
}
else {
  // hide all elements that don't share ourClass
  $('#projects').children('li:not(.' + ourClass + ')').animate({opacity:0.15}, 400);
  // show all elements that do share ourClass
  $('#projects').children('li.' + ourClass).animate({opacity:1}, 400);
}
return false;
});`

关于jquery - 使用 jquery 改变不透明度的数据过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15424638/

相关文章:

javascript - meteor 和 react : Correct way to manipulate elements on click?

javascript - 使用 jquery 时未检测到全局变量但没有错误

css - Polymer 的纸 slider 我想更改拖动轴

javascript - 在一定时间内自动减小图像尺寸

从数据框中删除仅包含 0 或仅包含单个 0 的行

android - 在 listview 上过滤自定义适配器在 android 中无法正常工作?

javascript - 过滤给定范围的对象数组

javascript - 使用 AJAX 加载图像时替换 CSS 背景

JavaScript/jQuery : How do you pass an element to a function as its 'this' ?

wordpress - 谷歌浏览器第一次访问时不会显示字体(css3、wordpress)。 (仅在刷新时)