Isotope: Select and display .xx class at the top

安稳与你 提交于 2019-12-05 06:55:42

问题


I'm using the sorting methods within Isotope (http://isotope.metafizzy.co/docs/sorting.html) and need to display elements with a specific CSS class name assigned to them at the top when a link is clicked. The remaining elements must remain visible beneath the sorted elements so I cannot use Isotope filtering.

I'm not so comfortable with JS/jQuery so I'm not even to sure if this code is even set out correctly but currently my elements are sorting by date which is great, however its doing this for all elements. I would like my code to find all elements with the class name of 'blogs' then arrange by date. This is my code so far:

    getSortData : {
      blogs : function( $elem ) {
        return $elem.attr('.blogs'), $elem.find('.date').text();
      }
    }

回答1:


Isotope does a normal sort based on the returned value of the function you provide.

So you need to return something that puts the .blog elements at the top ..

I am assuming that for date only you used $elem.find('.date').text()

So to alter this you can just add a space at the beginning for elements that are .blog

Try

getSortData : {
  blogs : function( $elem ) {
    var isBlog = $elem.hasClass('blogs');
    return (isBlog?' ':'') + $elem.find('.date').text();
  }
}

Update for comments

    sortBy: 'initial',
    sortAscending : false,
    itemSelector: '.module',
    getSortData: {
        initial: function($elem) {
            return $elem.find('.date').text();
        },
        blogs: function($elem) {
            var isBlog = $elem.hasClass('blogs');
            return (isBlog ? '9' : '') + $elem.find('.date').text();
        },


来源:https://stackoverflow.com/questions/9700295/isotope-select-and-display-xx-class-at-the-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!