我有一个页面中的项目列表,必须按顺序隐藏,但在上一个项目完全隐藏之后.
我做了以下代码,在那里我创建了一个大字符串,在前面的回调中插入回调,然后使用eval来执行效果,但是尽管代码工作正常,但我完全相信这不是最好的方法.这个.
// get items to hide
var itemsToHide = jQuery(".hide");
// function responsible to hide the item
var hideItem = function (item, callback) {
jQuery(item).hide(100, callback)
};
// declare an empty function, to be the first to be called
var buff = function(){};
for (var i = 0; i < itemsToHide.length; i++) {
// put the previous value of buff in the callback and assign this to buff
buff = "function(){hideItem(itemsToHide[" + i + "], " + buff + …Run Code Online (Sandbox Code Playgroud)