javascript Isotope.js

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Isotope.js相关的知识,希望对你有一定的参考价值。

var $container = $('.grid').isotope({
			itemSelector: '.project-item'
		});


		// filter with selects and checkboxes
		var $selects = $('select');

		$selects.change( function() {
			// map input values to an array
			var exclusives = [];
			var inclusives = [];
			// exclusive filters from selects
			$selects.each( function( i, elem ) {
				if ( elem.value ) {
					exclusives.push( elem.value );
				}
			});

			// combine exclusive and inclusive filters

			// first combine exclusives
			exclusives = exclusives.join('');

			var filterValue;
			if ( inclusives.length ) {
				// map inclusives with exclusives for
				filterValue = $.map( inclusives, function( value ) {
					return value + exclusives;
				});
				filterValue = filterValue.join(', ');
			} else {
				filterValue = exclusives;
			}

			$container.isotope({ filter: filterValue })
		});
// external js: isotope.pkgd.js

// init Isotope
var $grid = $('.project-posts .grid').isotope({
  itemSelector: '.project-item'
});

// store filter for each group
var filters = {};

$('.filters').on( 'click', '.button', function( event ) {
  var $button = $( event.currentTarget );
  // get group key
  var $buttonGroup = $button.parents('.button-group');
  var filterGroup = $buttonGroup.attr('data-filter-group');
  // set filter for group
  filters[ filterGroup ] = $button.attr('data-filter');
  // combine filters
  var filterValue = concatValues( filters );
  // set filter for Isotope
  $grid.isotope({ filter: filterValue });
});

// change is-checked class on buttons
$('.button-group').each( function( i, buttonGroup ) {
  var $buttonGroup = $( buttonGroup );
  $buttonGroup.on( 'click', 'button', function( event ) {
    $buttonGroup.find('.is-checked').removeClass('is-checked');
    var $button = $( event.currentTarget );
    $button.addClass('is-checked');
  });
});

// flatten object by concatting values
function concatValues( obj ) {
  var value = '';
  for ( var prop in obj ) {
    value += obj[ prop ];
  }
  return value;
}

以上是关于javascript Isotope.js的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 isotope.js 制作具有多个 slectbox 的搜索过滤器?

JavaScript介绍

javascript的题。

javascript JavaScript isset()等效: - JavaScript

JavaScript 使用JavaScript更改CSS(JavaScript)

JavaScript之基础-1 JavaScript(概述基础语法)