2017-09-01 124 views
0

我想要使用過濾器的縮略圖在我的網站上工作。我一直在使用這一個at codepen作爲靈感。它在codepen中沒有任何問題,但是儘快將代碼插入到我的WordPress站點中(使用divi主題),過濾根本不起作用。縮略圖投資組合過濾器行爲不正確

在下面的代碼我從改變了風格#port#portiz.btn.butn。我做了這個改變,因爲我注意到它覆蓋了現有的樣式,我也想測試這是否是問題。我也對JS和HTML進行了相同的更改。

我不知道在哪裏或要改變什麼,或添加。

最佳, 雷

<script> 
 
$(function() { 
 
\t \t var selectedClass = ""; 
 
\t \t $(".fil-cat").click(function(){ 
 
\t \t selectedClass = $(this).attr("data-rel"); 
 
    $("#portiz").fadeTo(100, 0.1); 
 
\t \t $("#portiz div").not("."+selectedClass).fadeOut().removeClass('scale-anm'); 
 
    setTimeout(function() { 
 
     $("."+selectedClass).fadeIn().addClass('scale-anm'); 
 
     $("#portiz").fadeTo(300, 1); 
 
    }, 300); 
 
\t \t 
 
\t }); 
 
}); 
 
</script>
#portiz{ 
 
    margin: 1rem 0; 
 
    -webkit-column-count: 3; 
 
    -moz-column-count: 3; 
 
    column-count: 3; 
 
    -webkit-column-gap: 1rem; 
 
    -moz-column-gap: 1rem; 
 
    column-gap: 1rem; 
 
    -webkit-column-width: 33.33333333333333%; 
 
    -moz-column-width: 33.33333333333333%; 
 
    column-width: 33.33333333333333%; 
 
} 
 
.tile { 
 
    -webkit-transform: scale(0); 
 
    transform: scale(0); 
 
    -webkit-transition: all 350ms ease; 
 
    transition: all 350ms ease; 
 

 
} 
 
.tile:hover { 
 

 
} 
 

 
.scale-anm { 
 
    transform: scale(1); 
 
} 
 

 
.tile img { 
 
    max-width: 100%; 
 
    width: 100%; 
 
    height: auto; 
 
    margin-bottom: 1rem; 
 
    
 
} 
 

 
.butn { 
 
    font-size: 1rem; 
 
    font-weight: normal; 
 
    text-decoration: none; 
 
    cursor: pointer; 
 
    display: inline-block; 
 
    line-height: normal; 
 
    padding: .5rem 1rem; 
 
    margin: 0; 
 
    height: auto; 
 
    border: 1px solid; 
 
    vertical-align: middle; 
 
    -webkit-appearance: none; 
 
    color: #555; 
 
    background-color: rgba(0, 0, 0, 0); 
 
} 
 

 
.butn:hover { 
 
    text-decoration: none; 
 
} 
 

 
.butn:focus { 
 
    outline: none; 
 
    border-color: var(--darken-2); 
 
    box-shadow: 0 0 0 3px var(--darken-3); 
 
} 
 

 
::-moz-focus-inner { 
 
    border: 0; 
 
    padding: 0; 
 
}
<div class="toolbar mb2 mt2"> 
 
    <button class="butn fil-cat" href="" data-rel="all">All</button> 
 
    <button class="butn fil-cat" data-rel="web">Websites</button> 
 
    <button class="butn fil-cat" data-rel="flyers">Flyers</button> 
 
    <button class="butn fil-cat" data-rel="bcards">Business Cards</button> 
 
</div> 
 
    
 
<div style="clear:both;"></div> 
 
<div id="portiz"> 
 
    <div class="tile scale-anm web all"> 
 
     <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/2-mon_1092-300x234.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm bcards all"> 
 
    <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/jti-icons_08-300x172.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm web all"> 
 
    <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/emi_haze-300x201.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm web all"> 
 
      <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/codystretch-300x270.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm flyers all"> 
 
     <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm bcards all"> 
 
      <img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm flyers all"> 
 
    <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/jti-icons_08-300x172.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm flyers all"> 
 
    <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/transmission_01-300x300.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm web all"> 
 
     <img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm flyers all"> 
 
      <img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm web all"> 
 
     <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/the-ninetys-brand_02-300x300.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm bcards all"> 
 
      <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/15-dia_1092-1-300x300.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm web all"> 
 
     <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm bcards all"> 
 
      <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/emi_haze-300x201.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm web all"> 
 
      <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/transmission_01-300x300.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm web all"> 
 
     <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm bcards all">  
 
      <img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" /> 
 
    </div> 
 
</div> 
 
<div style="clear:both;"></div>

回答

0

你的JS是有點凌亂,但很有效。你只需要在你的SO片斷幾個錯誤:

  1. 您shoudn't包括在JS編輯
  2. 你忘了包括jQuery的,所以在你的例子是沒有定義$<script></script>標籤。

除此之外,它的工作原理:

$(function() { 
 
\t \t var selectedClass = ""; 
 
\t \t $(".fil-cat").click(function(){ 
 
\t \t selectedClass = $(this).attr("data-rel"); 
 
    $("#portiz").fadeTo(100, 0.1); 
 
\t \t $("#portiz div").not("."+selectedClass).fadeOut().removeClass('scale-anm'); 
 
    setTimeout(function() { 
 
     $("."+selectedClass).fadeIn().addClass('scale-anm'); 
 
     $("#portiz").fadeTo(300, 1); 
 
    }, 300); 
 
\t \t 
 
\t }); 
 
});
#portiz{ 
 
    margin: 1rem 0; 
 
    -webkit-column-count: 3; 
 
    -moz-column-count: 3; 
 
    column-count: 3; 
 
    -webkit-column-gap: 1rem; 
 
    -moz-column-gap: 1rem; 
 
    column-gap: 1rem; 
 
    -webkit-column-width: 33.33333333333333%; 
 
    -moz-column-width: 33.33333333333333%; 
 
    column-width: 33.33333333333333%; 
 
} 
 
.tile { 
 
    -webkit-transform: scale(0); 
 
    transform: scale(0); 
 
    -webkit-transition: all 350ms ease; 
 
    transition: all 350ms ease; 
 

 
} 
 
.tile:hover { 
 

 
} 
 

 
.scale-anm { 
 
    transform: scale(1); 
 
} 
 

 
.tile img { 
 
    max-width: 100%; 
 
    width: 100%; 
 
    height: auto; 
 
    margin-bottom: 1rem; 
 
    
 
} 
 

 
.butn { 
 
    font-size: 1rem; 
 
    font-weight: normal; 
 
    text-decoration: none; 
 
    cursor: pointer; 
 
    display: inline-block; 
 
    line-height: normal; 
 
    padding: .5rem 1rem; 
 
    margin: 0; 
 
    height: auto; 
 
    border: 1px solid; 
 
    vertical-align: middle; 
 
    -webkit-appearance: none; 
 
    color: #555; 
 
    background-color: rgba(0, 0, 0, 0); 
 
} 
 

 
.butn:hover { 
 
    text-decoration: none; 
 
} 
 

 
.butn:focus { 
 
    outline: none; 
 
    border-color: var(--darken-2); 
 
    box-shadow: 0 0 0 3px var(--darken-3); 
 
} 
 

 
::-moz-focus-inner { 
 
    border: 0; 
 
    padding: 0; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="toolbar mb2 mt2"> 
 
    <button class="butn fil-cat" href="" data-rel="all">All</button> 
 
    <button class="butn fil-cat" data-rel="web">Websites</button> 
 
    <button class="butn fil-cat" data-rel="flyers">Flyers</button> 
 
    <button class="butn fil-cat" data-rel="bcards">Business Cards</button> 
 
</div> 
 
    
 
<div style="clear:both;"></div> 
 
<div id="portiz"> 
 
    <div class="tile scale-anm web all"> 
 
     <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/2-mon_1092-300x234.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm bcards all"> 
 
    <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/jti-icons_08-300x172.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm web all"> 
 
    <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/emi_haze-300x201.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm web all"> 
 
      <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/codystretch-300x270.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm flyers all"> 
 
     <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm bcards all"> 
 
      <img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm flyers all"> 
 
    <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/jti-icons_08-300x172.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm flyers all"> 
 
    <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/transmission_01-300x300.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm web all"> 
 
     <img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm flyers all"> 
 
      <img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm web all"> 
 
     <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/the-ninetys-brand_02-300x300.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm bcards all"> 
 
      <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/15-dia_1092-1-300x300.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm web all"> 
 
     <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm bcards all"> 
 
      <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/emi_haze-300x201.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm web all"> 
 
      <img src="http://demo.themerain.com/charm/wp-content/uploads/2015/04/transmission_01-300x300.jpg" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm web all"> 
 
     <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97190&w=350&h=190" alt="" /> 
 
    </div> 
 
    <div class="tile scale-anm bcards all">  
 
      <img src="https://placeholdit.imgix.net/~text?txtsize=19&txt=200%C3%97290&w=200&h=290" alt="" /> 
 
    </div> 
 
</div> 
 
<div style="clear:both;"></div>