我试图在jQuery 1.5中使用Remy Sharp的Simple Spy(http://jqueryfordesigners.com/simple-jquery-spy-effect)。它在1.4下正常工作,但在1.5中,第一个消失后不会加载任何其他注释。jQuery Simple Spy不再适用于jQuery 1.5
任何人都可以看到什么需要更新的代码,所以它将与1.5工作?
$(function() {
$('ul.spy').simpleSpy();
});
(function ($) {
$.fn.simpleSpy = function (limit, interval) {
limit = limit || 4;
interval = interval || 4000;
return this.each(function() {
// 1. setup
// capture a cache of all the list items
// chomp the list down to limit li elements
var $list = $(this),
items = [], // uninitialised
currentItem = limit,
total = 0, // initialise later on
height = $list.find('> li:first').height();
// capture the cache
$list.find('> li').each(function() {
items.push('<li>' + $(this).html() + '</li>');
});
total = items.length;
$list.wrap('<div class="spyWrapper" />').parent().css({ height : height * limit });
$list.find('> li').filter(':gt(' + (limit - 1) + ')').remove();
// 2. effect
function spy() {
// insert a new item with opacity and height of zero
var $insert = $(items[currentItem]).css({
height : 0,
opacity : 0,
display : 'none'
}).prependTo($list);
// fade the LAST item out
$list.find('> li:last').animate({ opacity : 0}, 1000, function() {
// increase the height of the NEW first item
$insert.animate({ height : height }, 1000).animate({ opacity : 1 }, 1000);
// AND at the same time - decrease the height of the LAST item
// $(this).animate({ height : 0 }, 1000, function() {
// finally fade the first item in (and we can remove the last)
$(this).remove();
// });
});
currentItem++;
if (currentItem >= total) {
currentItem = 0;
}
setTimeout(spy, interval)
}
spy();
});
};
})(jQuery);
我已经公布了它JSBin副本,你可以看到发生了什么:
这里有一个工作版本与旧版本的jQuery:
http://jqueryfordesigners.com/demo/simple-spy.html
这是什么意思“它在第一个消失后不加载任何额外的评论”?你能更详细地描述错误的性质吗?你看到控制台中记录的任何错误吗? – treeface 2011-02-15 18:59:22
我编辑过我的帖子,所以你可以看到一个工作演示和一个与jQuery 1.5(可以在JSBin上编辑)。正如你所看到的,评论在消失后不再出现。 – Cofey 2011-02-15 19:03:38