0

我正在建立一个带有可过滤项目的网站。我基本上想改变过滤类中元素的不透明度。因此,具有“活动”类的 100% 不透明度元素,以及没有“活动”类的所有其他元素的 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;
  });
});
4

1 回答 1

1
 $('#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;
});`
于 2013-03-18T00:49:08.627 回答