简体   繁体   English

新添加的div上的jQuery slideDown

[英]jQuery slideDown on newly appended div

I'm trying to use the jQuery slideDown() effect on my new appended <div> 's. 我正在尝试在新添加的<div>上使用jQuery slideDown()效果。

Here is my Javascript code. 这是我的Javascript代码。

$.ajax({
    type: "GET",
    url: "/loadmore/dj/",
    data: {
        'slug': $('.dj_slug').text().trim(),
        'song_rank': $("#dj_song_list").find('.song_block').length
    },
}).done(function (response) {
    $('#dj_song_list').append(response).hide().slideDown(1000);
});

This works but the slideDown() is applied to the entire #dj_song_list and not just the appended <div> 's. 这有效,但是slideDown()应用于整个#dj_song_list而不是仅应用于附加的<div> How can I apply it to just the newly appended <div> 's? 如何将其仅应用于新添加的<div>

Here is my HTML structure for reference 这是我的HTML结构供参考

<div id='dj_song_list'>
    {% include 'hunt/songs_dj.html' %}
</div>

songs_dj.html songs_dj.html

<div class="song_block">
    ...
    ...
    ...
</div>

You want to do this: 您想这样做:

$.ajax({
    type: "GET",
    url: "/loadmore/dj/",
    data: {
        'slug': $('.dj_slug').text().trim(),
        'song_rank': $("#dj_song_list").find('.song_block').length
    },
    dataType: 'html'
}).done(function (response) {
    $(response).appendTo($('#dj_song_list')).hide().slideDown(1000);
});

Check this fiddle: 检查这个小提琴:

http://jsfiddle.net/7cws8/1/ http://jsfiddle.net/7cws8/1/

I have done exactly what you want: 我已经完全按照您的意愿做了:

Also for your code you can append response to a hidden div and then can slide it down: 同样对于您的代码,您可以将响应附加到隐藏的div,然后将其向下滑动:

$.ajax({
    type: "GET",
    url: "/loadmore/dj/",
    data: {
        'slug': $('.dj_slug').text().trim(),
        'song_rank': $("#dj_song_list").find('.song_block').length
    },
}).done(function (response) {
    $('#dj_song_list').append("<div id='response-content' style='display:none;'>"+response+"</div>");

$("#response-content").slideDown(1000);

});

Change this: 更改此:

 $('#dj_song_list').append(response).hide().slideDown(1000);

Into this: 变成这个:

 $('#dj_song_list').append(response);
 $('#dj_song_list').find('div').last().hide().slideDown(1000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM