jQueryプラグイン"shuffle.js"を用いたAND検索の実装について
記事を設定したラベルでフィルタリングするページを作成しています。
例えばラベルAとラベルB,両方の属性を持つを絞りたいといった感じです。
ラベルAだけといった単一のラベルを用いた絞り込みはできているのですが,2つ以上のラベルの実装で行き詰まっています
二つ目のボタンを押すとそれ以前に押したラベルのアクティブ状態がクリアされる
<script> $(function() { //ボタンが押されたときの処理 $('#btn li').on('click', function() { var $this = $(this), $grid = $('#animationList'); $('#btn .active').removeClass('active') $this.addClass('active'); $grid.shuffle($this.data('group')); }); $('#animationList').shuffle({ group: 'all', speed: 700, easing: 'ease-in-out' }); }); </script>
HTML
HTML
1</head> 2<body> 3<div id="wrapper"> 4 <h1>Search Field</h1> 5 <ul id="btn"> 6 <li data-group="health" name="health" id="health"># Health Care</li> 7 <li data-group="learning" name="learning" id="learning"># Learning / Optimization</li> 8 <li data-group="stim" name="stim" id="stim"># Electrical Stimulation</li> 9 </ul> 10 <ul id="btn"> 11 <li data-group="robot" name="robot" id="robot"># Robotics</li> 12 <li data-group="vrar" name="vrar" id="vrar"># VR / AR</li> 13 <li data-group="autonomous" name="autonomous" id="autonomous"># Autonomous Control</li> 14 </ul> 15 <ul id="btn"> 16 <li data-group="ah" name="ah" id="ah"># Human Augumentation</li> 17 <li data-group="is" name="is" id="is"># Real Work Space</li> 18 <li data-group="sc" name="sc" id="sc"># Smart Charging</li> 19 </ul> 20</br> 21</br> 22<h1>Our Research</h1> 23</hr> 24</br> 25</br> 26 <ul id="animationList" style="position: relative; transition: height 700ms ease-in-out 0s; height: 720px;"> 27 <li data-groups="["health","ah","stim","vrar"]" class="filtered" data-x="0" data-y="0" style="position: absolute; top: 0px; left: 0px; opacity: 1; transition: transform 700ms ease-in-out 0s, opacity 700ms ease-in-out 0s; margin-top: 0px; margin-right: 0px; transform: translate3d(0px, 0px, 0px) scale3d(1, 1, 1);"><span class="grey">記事A</span></li> 28 <li data-groups="["learning","ah","stim","vrar"]" class="filtered" data-x="240" data-y="0" style="position: absolute; top: 0px; left: 0px; opacity: 1; transition: transform 700ms ease-in-out 0s, opacity 700ms ease-in-out 0s; margin-top: 0px; margin-right: 0px; transform: translate3d(240px, 0px, 0px) scale3d(1, 1, 1);"><span class="grey">Motionless</span></li> 29 <li data-groups="["is","ah","vrar"]" class="filtered" data-x="480" data-y="0" style="position: absolute; top: 0px; left: 0px; opacity: 1; transition: transform 700ms ease-in-out 0s, opacity 700ms ease-in-out 0s; margin-top: 0px; margin-right: 0px; transform: translate3d(480px, 0px, 0px) scale3d(1, 1, 1);"><span class="grey">記事B</span></li> 30 <li data-groups="["ah","vrar"]" class="filtered" data-x="720" data-y="0" style="position: absolute; top: 0px; left: 0px; opacity: 1; transition: transform 700ms ease-in-out 0s, opacity 700ms ease-in-out 0s; margin-top: 0px; margin-right: 0px; transform: translate3d(720px, 0px, 0px) scale3d(1, 1, 1);"><span class="grey">記事C</span></li> 31 <li data-groups="["learning","health","ah","stim"]" class="filtered" data-x="0" data-y="240" style="position: absolute; top: 0px; left: 0px; opacity: 1; transition: transform 700ms ease-in-out 0s, opacity 700ms ease-in-out 0s; margin-top: 0px; margin-right: 0px; transform: translate3d(0px, 240px, 0px) scale3d(1, 1, 1);"><span class="grey">記事D</span></li> 32 <li data-groups="["is","learning","health"]" class="filtered" data-x="240" data-y="240" style="position: absolute; top: 0px; left: 0px; opacity: 1; transition: transform 700ms ease-in-out 0s, opacity 700ms ease-in-out 0s; margin-top: 0px; margin-right: 0px; transform: translate3d(240px, 240px, 0px) scale3d(1, 1, 1);"><span class="grey">記事E</span></li> 33 <li data-groups="["robot","is","learning"]" class="filtered" data-x="480" data-y="240" style="position: absolute; top: 0px; left: 0px; opacity: 1; transition: transform 700ms ease-in-out 0s, opacity 700ms ease-in-out 0s; margin-top: 0px; margin-right: 0px; transform: translate3d(480px, 240px, 0px) scale3d(1, 1, 1);"><span class="grey">記事F</span></li> 34 <li data-groups="["sc","autonomous","robot","is"]" class="filtered" data-x="720" data-y="240" style="position: absolute; top: 0px; left: 0px; opacity: 1; transition: transform 700ms ease-in-out 0s, opacity 700ms ease-in-out 0s; margin-top: 0px; margin-right: 0px; transform: translate3d(720px, 240px, 0px) scale3d(1, 1, 1);"><span class="grey">記事G</span></li> 35 <li data-groups="["sc","autonomous","learning"]" class="filtered" data-x="0" data-y="480" style="position: absolute; top: 0px; left: 0px; opacity: 1; transition: transform 700ms ease-in-out 0s, opacity 700ms ease-in-out 0s; margin-top: 0px; margin-right: 0px; transform: translate3d(0px, 480px, 0px) scale3d(1, 1, 1);"><span class="grey">記事H</span></li> 36 <li data-groups="["sc","autonomous","is"]" class="filtered" data-x="240" data-y="480" style="position: absolute; top: 0px; left: 0px; opacity: 1; transition: transform 700ms ease-in-out 0s, opacity 700ms ease-in-out 0s; margin-top: 0px; margin-right: 0px; transform: translate3d(240px, 480px, 0px) scale3d(1, 1, 1);"><span class="grey">記事I</span></li> 37 </ul> 38</div> 39</body></html>
CSS
CSS
1/* html5 2---------------------------------------------------------------*/ 3article, 4aside, 5details, 6figcaption, 7figure, 8footer, 9header, 10hgroup, 11menu, 12nav, 13section { 14 display: block; 15 margin: 0; 16 padding: 0; 17} 18body { 19 background-color: #f6f6f6; 20} 21#wrapper { 22 width: 1360px; 23 margin: 0 auto; 24 color: #7d7d7d; 25 padding-top: 30px; 26 padding-bottom: 60px; 27} 28h1 { 29 margin: 50px 0 70px; 30} 31.alpha { 32 display: inline-block\9; 33 zoom: 1; 34 line-height: 1; 35} 36.alpha:hover { 37 opacity: 0.9; 38 filter: alpha(opacity=70); 39} 40.active { 41 background-color: #EEEEEE; 42 color:#ff8c00; 43} 44#btn { 45 overflow: hidden; 46 margin-top: 50px; 47 margin-bottom: 40px; 48 display: : inline-block; 49 font-size: 22px; 50 cursor: pointer; 51} 52#btn li { 53 float: left; 54 margin: 10px; 55 cursor: pointer; 56 border: solid; 57 border-width: 2px; 58 padding: 10px; 59 box-shadow: 2px 2px 4px #808080; 60} 61#animationList { 62 overflow: hidden; 63} 64#animationList li { 65 width: 390px; 66 height: 390px; 67 padding: 10px; 68 float: left; 69 color: #fff; 70} 71#animationList li span { 72 display: block; 73 width: 360px; 74 height: 340px; 75 padding: 20px; 76} 77.box_image{ 78 height: 220px; 79 overflow-x: hidden; 80 overflow-y: hidden; 81} 82.red { 83 background-color: #cf0000; 84} 85.blue { 86 background-color: #0208da; 87} 88.green { 89 background-color: #2baa08; 90} 91.yellow { 92 background-color: #e8ec04; 93} 94.grey{ 95 background-color: #555555; 96} 97/* Reset 98------------------------------------------------------------*/ 99body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, form, fieldset, input, textarea, p, blockquote, th, td { 100 margin: 0; 101 padding: 0; 102} 103address, em, strong, th { 104 font-style: normal; 105} 106table { 107 border-collapse: collapse; 108 border-spacing: 0; 109} 110th { 111 text-align: left; 112} 113hr, legend { 114 display: none; 115} 116h1, h2, h3, h4, h5, h6 { 117 font-size: 100%; 118} 119img { 120 border: 0; 121 vertical-align: middle; 122} 123li { 124 list-style-type: none; 125} 126/* Fonts 127------------------------------------------------------------*/ 128body { 129 font-family: "ヒラギノ角ゴ Pro W3","Hiragino Kaku Gothic Pro",Osaka,"MS Pゴシック","MS PGothic",Arial,Helvetica,Verdana,sans-serif; 130 line-height: 1.5; 131 color: #313131; 132} 133/* clearfix 134------------------------------------------------------------*/ 135.clearfix:after { 136 content: ""; 137 display: block; 138 font-size: 0; 139 visibility: hidden; 140 height: 0; 141 clear: both; 142} 143/* clearfix for IE7 */ 144.clearfix { 145 display: inline-block; 146} 147.clearfix { 148 display: block; 149}
参考サイト
元のコードは以下のサイトから引っ張ってきました。
N - log.net