using quicksand plugin to get specific data

徘徊边缘 提交于 2019-12-08 09:12:50

问题


Can anybody help me with the quicksand plugin, I am trying to load the web data-value first not the all data-value that is loaded on pageload.The idea is when I click on my drop down menu for instance Web design the web.html already has the web projects loaded not the all value that is under the default.This is my html: Thanks!

<div id="smoothmenu1" class="ddsmoothmenu"> 
  <ul>
    <li>Home</li>
    <li>Design
      <ul>
        <li>Web design</li>
        <li>Banners</li>
        <li>Posters</li>

      </ul>
    </li>
    <li>Video<
      <ul>
        <li>Category 1</li>
        <li>Category 2</li>
        <li>Category 3</li>
      </ul>
    </li>
    <li>Games</li>

    <li>Contact</li>
  </ul>
<ul id="content" class="gallerynav">

<li class="selected-1 button2">< data-value="all">All</li>
<li class="button2">< data-value="web">Web Design</li>
<li class="button2">< data-value="photo">Banners</li>
<li class="button2"><  data-value="video">Posters</li>

 <ul id="gallery" class="qsmall">
    <li data-id="id-1" class="web"> <span class="qcaption peek"> <span class="meta"> <span class="name">Om Du Möter Varg</span></span>
<a href rel="zoombox[web]" title="Om Du Möter Varg"> </a></li></ul>

and so on.
and my javascript file:

$(function() {

  var read_button = function(class_names) {
    var r = {
      selected: false,
      type: 0
    };
    for (var i=0; i < class_names.length; i++) {
      if (class_names[i].indexOf('selected-') == 0) {
        r.selected = true;
      }
      if (class_names[i].indexOf('segment-') == 0) {
        r.segment = class_names[i].split('-')[1];
      }
    };
    return r;
  };

  var determine_sort = function($buttons) {
    var $selected = $buttons.parent().filter('[class*="selected-"]');
    return $selected.find('a').attr('data-value');
  };

  var determine_kind = function($buttons) {
    var $selected = $buttons.parent().filter('[class*="selected-"]');
    return $selected.find('a').attr('data-value');
  };

  var $preferences = {
    duration: 800,
    easing: 'easeInOutQuad',
    adjustHeight: false
  };

  var $list = $('#gallery');
  var $data = $list.clone();

  var $controls = $('ul.gallerynav');

  $controls.each(function(i) {

    var $control = $(this);
    var $buttons = $control.find('a');

    $buttons.bind('click', function(e) {

  var $button = $(this);
  var $button_container = $button.parent();
  var button_properties = read_button($button_container.attr('class').split(' '));      
  var selected = button_properties.selected;
  var button_segment = button_properties.segment;

  if (!selected) {

    $buttons.parent().removeClass('selected-1'); $button_container.addClass('selected-' + 1);

    var sorting_type = determine_sort($controls.eq(1).find('a'));
    var sorting_kind = determine_kind($controls.eq(0).find('a'));

    if (sorting_kind == 'all') {
      var $filtered_data = $data.find('li');
    } else {
      var $filtered_data = $data.find('li.' + sorting_kind);
    }

    if (sorting_type == 'size') {
      var $sorted_data = $filtered_data.sorted({
        by: function(v) {
          return parseFloat($(v).find('span').text());
        }
      });
    } else {
      var $sorted_data = $filtered_data.sorted({
        by: function(v) {
          return $(v).find('strong').text().toLowerCase();
        }
      });
    }

    $list.quicksand($sorted_data, {
  enhancement: function() {
  zoombox.init();
}

}, function() {

$('.qcaption.peek').hover(function(){
    $(".cover", this).stop().animate({top:'25px'},{queue:false,duration:160});
}, function() {
$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
    });
});

}

  e.preventDefault();
});

});

});


回答1:


This is what I did:

<script type="text/javascript">
   $(document).ready(function() {
      $(".class").trigger('click');
   });
</script>

It's probably not the best solution but it worked for me. .class has to be the class of the link you'll replicate with trigger. This way you fake a click on that anchor when you load the page to make quicksand believe that you actually clicked there.



来源:https://stackoverflow.com/questions/4328140/using-quicksand-plugin-to-get-specific-data

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