新的列表项由JS生成。 每个新的列表项都带有一个漂亮的动画。现在我不想在第一个列表项上看到动画。
到目前为止,我尝试将slice(1)
添加到代码中,但没有运气:
$('li.show').slice(1).animate({left: '-=100'}, 300);
如何使用最新版本的JQuery来完成这项工作?
答案 0 :(得分:1)
如果您正在使用AJAX请求来构建列表,那么您需要调用在AJAX请求的回调函数中发布的代码,以便在尝试操作之前添加的HTML将出现在DOM中:< / p>
$.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。