Javascript回调函数

时间:2012-04-19 06:05:21

标签: javascript

我在测试页面上使用了Lazy Load Jquery插件:http://bloghutsbeta.blogspot.com/2012/03/testing-2_04.html 这是lazyload的缩小脚本: 代码:

<script src="http://files.cryoffalcon.com/javascript/jquery.lazyload.min.js" type="text/javascript" charset="utf-8"></script>

这个是触发延迟加载: 代码:

<script type="text/javascript" charset="utf-8">
      $(function() {
          $("img").lazyload({
     effect : "fadeIn"
 });
      });
  </script>

在上面的脚本中我添加了fadeIn效果,我不知道我是否按照脚本编写做得对,我不擅长脚本^^所以,如果写的很好,我想建议一下或者有一些逗号错误。

但这不是我的重要问题,所有上述延迟加载插件都与我用于排序的QuickSand Jquery插件一起使用。 QuickSand Jquery插件需要回调函数,如果它是工具提示或延迟加载,那么有人可以告诉我如何使懒惰加载与quicksand jquery一起工作。 这是流沙的剧本:

代码:

&lt;script type=&quot;text/javascript&quot;&gt;
(function(cash) {
 $.fn.sorted = function(customOptions) {
  var options = {
   reversed: false,
   by: function(a) {
    return a.text();
   }
  };
  $.extend(options, customOptions);

  $data = $(this);
  arr = $data.get();
  arr.sort(function(a, b) {

      var valA = options.by($(a));
      var valB = options.by($(b));
   if (options.reversed) {
    return (valA &lt; valB) ? 1 : (valA &gt; valB) ? -1 : 0;    
   } else {  
    return (valA &lt; valB) ? -1 : (valA &gt; valB) ? 1 : 0; 
   }
  });
  return $(arr);
 };

})(jQuery);

$(function() {

  var read_button = function(class_names) {
    var r = {
      selected: false,
      type: 0
    };
    for (var i=0; i &lt; 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*=&quot;selected-&quot;]');
    return $selected.find('a').attr('data-value');
  };

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

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

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

  var $controls = $('ul#gamecategories ul');

  $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-0').removeClass('selected-1').removeClass('selected-2');
        $button_container.addClass('selected-' + button_segment);

        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, $preferences, function () { $(this).tooltip (); } );

      }

      e.preventDefault();
    });

  }); 

var high_performance = true;  
  var $performance_container = $('#performance-toggle');
  var $original_html = $performance_container.html();

  $performance_container.find('a').live('click', function(e) {
    if (high_performance) {
      $preferences.useScaling = false;
      $performance_container.html('CSS3 scaling turned off. Try the demo again. &lt;a href=&quot;#toggle&quot;&gt;Reverse&lt;/a&gt;.');
      high_performance = false;
    } else {
      $preferences.useScaling = true;
      $performance_container.html($original_html);
      high_performance = true;
    }
    e.preventDefault();
  });
});
&lt;/script&gt;

1 个答案:

答案 0 :(得分:0)

你可以用这个:

$list.quicksand($sorted_data, $preferences, function(){
    $(this).tooltip ();
    $("img").lazyload({
        effect : "fadeIn"
    });
});