新的列表项由JS生成。每一个新的列表项都有一个漂亮的动画。现在我不想在第一个列表项上看到动画。
到目前为止,我尝试将slice(1)
添加到代码中,但没有成功:
$('li.show').slice(1).animate({left: '-=100'}, 300);
如何使用最新版本的JQuery实现此功能?
发布于 2012-01-09 22:35:36
如果您使用AJAX请求来构建列表,那么您将需要调用在AJAX请求的回调函数中发布的代码,以便在您尝试操作它之前,添加的HTML将出现在DOM中:
$.get('<URL>', function (serverResponse) {
//append the new list-items to the list, select them, un-select the first index, then animate the remaining elements
$('ul').append(serverResponse).children('.show').slice(1).animate({left: '-=100'}, 300);
});
注意,这段代码期望您的服务器端脚本输出可以直接添加到DOM中的有效HTML。
https://stackoverflow.com/questions/8796012
复制