我正在按日期对 div 网格进行排序,但遇到了问题。div 是按日期排序的,但是当您引入另一个月份时,它不会考虑到这一点,而只是按天值排序。
HTML:
<div class="grid-filter">
<a href="#">
<div class="grid-block" style="background-color: #46747c" data-category="1952013">
<div class="block-text date-title">19/05</div>
</div>
</a>
</div>
<div class="grid-filter">
<a href="#">
<div class="grid-block" style="background-color: #ebd133" data-category="2552013">
<div class="block-text date-title">25/05</div>
</div>
</a>
</div>
<div class="grid-filter">
<a href="#">
<div class="grid-block" style="background-color: #cc7788" data-category="3052013">
<div class="block-text date-title">30/05</div>
</div>
</a>
</div>
<div class="grid-filter">
<a href="#">
<div class="grid-block" style="background-color: #46747c" data-category="0562013">
<div class="block-text date-title">05/06</div>
</div>
</a>
</div>
jQuery
jQuery(document).ready(function(){
var jQuerycontainer = jQuery('#main-grid');
if(location.hash!=""){
var hashfilter = "." + location.hash.substr(1);
}
else{
var hashfilter = "*";
}
jQuerycontainer.imagesLoaded( function(){
jQuerycontainer.isotope({
filter: hashfilter,
itemSelector: '.grid-block',
getSortData : {
date : function( jQueryelem ) {
return jQueryelem.attr('data-category');
}
},
sortBy : 'date',
animationEngine: 'css',
masonry: {
columnWidth: 4
}
});
});
jQuery('.filter-menu a').click(function(){
var selector = jQuery(this).attr('data-filter');
var prettyselector = selector.substr(1);
location.hash = prettyselector;
jQuery('html, body').animate({scrollTop:0}, 'slow');
return false;
});
jQuery('.grid-filter a').click(function(){
var selector = jQuery(this).attr('data-filter');
var prettyselector = selector.substr(1);
location.hash = prettyselector;
jQuery('html, body').animate({scrollTop:0}, 'slow');
return false;
});
jQuery(window).hashchange(function(){
if(location.hash!=""){
var hashfilter = "." + location.hash.substr(1);
}
else{
var hashfilter = "*";
}
jQuerycontainer.imagesLoaded( function(){
jQuerycontainer.isotope({
filter: hashfilter,
itemSelector: '.grid-block',
getSortData : {
date : function( jQueryelem ) {
return jQueryelem.attr('data-category');
}
},
sortBy : 'date',
animationEngine: 'css',
masonry: {
columnWidth: 4
}
});
});
});
});
所以正在对块进行排序,但最后一个带有日期的块0562013
首先出现,因为 05 是我假设的最小数字,无论如何也要考虑月份,所以它会按日期成功对 div 进行排序?