2012-06-05 30 views
0

我正在使用流沙和jquery的可過濾網站上工作。我已經設置了一切(imgs現在是通用的)。在一組圖像上方有一組類別,當您選擇一個類別時,只顯示該類別中的項目。它過濾並顯示正確的項目,但在過濾時它以非常尷尬的方式上下跳動 - 何時應該緩解。使用jQuery流沙過濾時的尷尬跳躍

鏈接是HTML的http://lllh.dk/filtering/work3.html

部分:

<div id="content"> 
    <div class="txtdiv"> 
    <h1>A selection of work</h1> 
    <h2>2009-present</h2> 
    </div> 

     <div id="workleft"> 

      <ul class="filterOptions"> 
       <txt> 
       <li class="active"><a href="#" class="all">All</a></li> 
       <li><a href="#" class="graphicdesign">Graphic Design</a></li> 
       <li><a href="#" class="printmatters">Design of Printed Matters</a></li> 
       <li><a href="#" class="designlanguages">Design for Languages</a></li> 
       <li><a href="#" class="typo">Typography and Lettering</a></li> 
       <li><a href="#" class="visualidentity">Visual Identity</a></li> 
       </txt> 
      </ul> 
     </div> 

     <div id="workright"> 
      <ul class="filterOptions"> 
       <txt> 
       <li><a href="#" class="photo">Photography</a></li> 
       <li><a href="#" class="camless">Cameraless Photography</a></li> 
       <li><a href="#" class="co-socialdesign">Co-Design/Social Design</a></li> 
       <li><a href="#" class="conceptualdesign">Conceptual Design</a></li> 
       <li><a href="#" class="criticaldesign">Critical Design</a></li> 
       </txt> 
      </ul> 
     </div> 

    <div class="workdiv"> 

    <ul class="ourHolder"> 

<li class="item" data-id="id-1" data-type="graphicdesign typo"> 
<a href="work/braille_calendar.html" onMouseOver="document.braille.src='workbuttons/braille2.jpg';" onMouseOut="document.braille.src='workbuttons/braille1.jpg';"> <img src="workbuttons/braille1.jpg" name="braille"> </a> 
</li> 
<li class="item" data-id="id-3" data-type="camless photo"> 
<a href="work/braille_calendar.html" onMouseOver="document.RapaNui.src='workbuttons/braille2.jpg';" onMouseOut="document.RapaNui.src='workbuttons/braille1.jpg';"> <img src="workbuttons/braille1.jpg" name="RapaNui"> </a> 
</li> 

<li class="item" data-id="id-2" data-type="graphicdesign"> 
<a href="work/braille_calendar.html" onMouseOver="document.Name.src='workbuttons/braille2.jpg';" onMouseOut="document.Name.src='workbuttons/braille1.jpg';"> <img src="workbuttons/braille1.jpg" name="Name"> </a> 
</li> 
<li class="item" data-id="id-2" data-type="typo"> 
<a href="work/braille_calendar.html" onMouseOver="document.Something.src='workbuttons/braille2.jpg';" onMouseOut="document.Something.src='workbuttons/braille1.jpg';"> <img src="workbuttons/braille1.jpg" name="Something"> </a> 
</li>   
    </ul> 
    </div> 
</div> 

以及一些CSS

/* Load headline fonts */ 
@font-face { 
font-family: 'ACPRegular'; 
src: url('acaslonpro-regular-webfont.eot'); 
src: url('acaslonpro-regular-webfont.eot?#iefix') format('embedded-opentype'), 
    url('acaslonpro-regular-webfont.woff') format('woff'), 
    url('acaslonpro-regular-webfont.ttf') format('truetype'); 
font-weight: normal; 
font-style: normal; 
} 
@font-face { 
font-family: 'ACPBold'; 
src: url('acaslonpro-bold-webfont.eot'); 
src: url('acaslonpro-bold-webfont.eot?#iefix') format('embedded-opentype'), 
    url('acaslonpro-bold-webfont.woff') format('woff'), 
    url('acaslonpro-bold-webfont.ttf') format('truetype'); 
font-weight: normal; 
font-style: normal; 
} 

/* Page content */ 
#content { 
margin-top:75px; 
position:absolute; 
width:850px; 
z-index:0; 
border-bottom:45px; 
border-bottom-style:solid; 
border-bottom-color:#FFF; 
} 

.txtdiv { 
width:400px; 
margin: 0px auto 0px auto; 
text-align:center; 
} 

/* Typography */ 

h1 { 
font-family:ACPBold; 
letter-spacing:1px; 
font-size:2em; 
font-weight:normal; 
padding:0px; 
margin:0px; 
margin-bottom:3px; 
} 

h2 { 
font-family:ACPRegular; 
font-size:1.2em; 
font-weight:normal; 
padding:0px; 
margin-top:0px; 
margin-bottom:15px; 
} 

txt { 
font-family:Arial, Helvetica, sans-serif; 
font-size:0.7em; 
line-height:160%; 
margin-left:auto; 
margin-right:auto; 
} 

ul { 
list-style-type: none; 
padding: 0px; 
margin: 0px; 
overflow: auto; 
} 

/* Work page */ 
#workleft { 
width:421px; 
margin: 0px 8px 0px 0px; 
text-align:right; 
float:left; 
} 

#workright { 
width:421px; 
text-align:left; 
overflow:hidden; 
} 


.workdiv { 
width:741px; 
margin: 0px auto 0px auto; 
margin-top:45px; 
} 

/*- PORTFOLIO -*/ 
ul.ourHolder { 
width: 800px; 
height: 850px; 
overflow: hidden; 
} 
ul.ourHolder li.item { 
width: 247px; 
height: 164px; 
float: left; 
text-align: center; 
overflow: hidden; 
} 

最後是JS的..

$(document).ready(function() { 
    // get the action filter option item on page load 
    var $filterType = $('.filterOptions li.active a').attr('class'); 

    // get and assign the portfolio element to the 
// $holder varible for use later 
    var $holder = $('ul.ourHolder'); 

    // clone all items within the pre-assigned $holder element 
    var $data = $holder.clone(); 

    // attempt to call Quicksand when a filter option 
// item is clicked 
$('.filterOptions li a').click(function(e) { 
    // reset the active class on all the buttons 
    $('.filterOptions li').removeClass('active'); 

    // assign the class of the clicked filter option 
    // element to our $filterType variable 
    var $filterType = $(this).attr('class'); 
    $(this).parent().addClass('active'); 

    if ($filterType == 'all') { 
     // assign all li items to the $filteredData var when 
     // the 'All' filter option is clicked 
     var $filteredData = $data.find('li'); 
    } 
    else { 
     // find all li elements that have our required $filterType 
     // values for the data-type element 
     var $filteredData = $data.find('li[data-type~=' + $filterType + ']'); 
    } 

    // call quicksand and assign transition parameters 
    $holder.quicksand($filteredData, { 
     duration: 800, 
     easing: 'easeInOutQuad' 
    }); 
    return false; 
}); 
}); 

看起來佈局的某些部分破壞了緩解。在我排除故障的嘗試中,似乎圖像上方的部分是問題,也許是txtdiv div。如果我除去適用於過濾器函數的所有css,則緩動和過濾都可以正常工作。

+0

在html中有一個錯誤;兩個「id-2」的實例,但不幸的是沒有解決跳躍式洗牌問題.. – Lilith

回答

0

我知道這個問題。 這裏已經是一個問題: CSS bubbling while using jQuery Quicksand

對於我來說它的工作原理,當我改變多個CSS線。但我不知道它了,也許你可以看看源:http://www.annagebhardt.de/(看到「PROJEKTE」,然後一個子項中的作用點擊)

+0

感謝您的回覆!從查看另一個問題及其答案,可以通過禁用'position:absolute'來解決,但是在我的情況下,這會導致佈局錯誤。也許我可以以某種方式避開。謝謝! – Lilith

0

註釋掉$(this).parent().addClass('active');並添加adjustHeight: false到流沙的選項爲我工作。