Facebook
From Tinct Coyote, 2 Years ago, written in HTML5.
Embed
Download Paste or View Raw
Hits: 189
  1. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  2. var searchBox = '.search-box';
  3. var searchItem = '.search-box input';
  4. var listItem = '.cat_image';
  5. var hideClass = 'is-hide';
  6.  
  7. $(function() {
  8.         $(searchItem).on('change', function() {
  9.                 search_filter();
  10.         });
  11. });
  12.  
  13. function search_filter() {
  14.         $(listItem).removeClass(hideClass);
  15.         for (var i = 0; i < $(searchBox).length; i++) {
  16.                 var name = $(searchBox).eq(i).find('input').attr('name');
  17.                 var searchData = selected_items(name);
  18.                 if(searchData.length === 0 || searchData[0] === '') {
  19.                         continue;
  20.                 }
  21.                 for (var j = 0; j < $(listItem).length; j++) {
  22.                         var itemData = $(listItem).eq(j).data(name);
  23.                         if(searchData.indexOf(itemData) === -1) {
  24.                                 $(listItem).eq(j).addClass(hideClass);
  25.                         }
  26.                 }
  27.         }
  28. }
  29.  
  30. function selected_items(name) {
  31.         var searchData = [];
  32.         $('input[name=' + name + ']:checked').each(function() {
  33.                 searchData.push($(this).val());
  34.         });
  35.         return searchData;
  36. }
  37.  
  38. .search-box_title{
  39.         font-weight: bold;
  40. }
  41. .search-box label {
  42.         cursor: pointer;
  43.         display: inline-block;
  44.         margin-right: 10px;
  45.         line-height: 16px;
  46. }
  47. .search-box input[type="radio"] {
  48.         width: 16px;
  49.         height: 16px;
  50.         margin: -2px 5px 0 0;
  51.         padding: 0;
  52.         box-sizing: border-box;
  53.         vertical-align: middle;
  54. }
  55. .search-box input[type="checkbox"] {
  56.         width: 16px;
  57.         height: 16px;
  58.         margin: -2px 5px 0 0;
  59.         padding: 0;
  60.         box-sizing: border-box;
  61.         vertical-align: middle;
  62. }
  63. .cat_image_all {
  64.         display: flex;
  65.         flex-wrap: wrap;
  66.         justify-content: space-between;
  67.         max-width: 680px;
  68.         margin: 3em auto 0;
  69. }
  70. .cat_image {
  71.         width: 48%;
  72.         max-width: 320px;
  73.         margin: 0 0 2em;
  74. }
  75. .cat_image.is-hide {
  76.         display: none;
  77. }
  78. .cat_image a {
  79.         display: block;
  80.         color: #444;
  81. }
  82. .cat_image a:hover {
  83.         text-decoration: underline;
  84. }
  85. </head>
  86. <body onload="search_filter()">
  87. <div class="search-box">
  88.         <span class="search-box_title">果物</span>
  89.         <label><input type="checkbox" name="fruits" value="apple">りんご</label>
  90.     <label><input type="checkbox" name="fruits" value="apple">バナナ</label>
  91.     <label><input type="checkbox" name="fruits" value="apple">マンゴー</label>
  92.     <label><input type="checkbox" name="fruits" value="orange">オレンジ</label>
  93.     <label><input type="checkbox" name="fruits" value="lemon">レモン</label>
  94. </div>
  95. <div class="cat_image_all">
  96.         <div class="cat_image" data-fruits="apple">
  97.                 <p>スムージー</p>
  98.         </div>
  99. </div>
  100. </body>
  101.  

Replies to Untitled rss

Title Name Language When
Re: Untitled Crippled Coyote html5 2 Years ago.