问题
I have a bootstrap modal that is used for comments. The comment form is appended at the bottom of the list of comments.
I want this modal to scroll to the bottom of the list, when it is opened, if there is more than 2 or 3 comments. I already have this slide plugin installed
http://jesseprice.com/jquery-slide-to-plugin/
Ideally i would like to be able to use that plugin. I have setup a Fiddle with my current ideas in it: http://jsfiddle.net/D2RLR/3275/
Here is my current jQuery
$('.slideto').slideto({
target : '.new-comment-entry',
speed : 'slow'
});
I have gotten this to work in the regualr browser window, but it wont attach to the modal.
If anyone wants a challenge, here ya go ;)
回答1:
Yes. Because you can't tell your modal body to scroll if that modal is not displayed already... You need to use some sort of callback function. Twitter Bootstrap provides you with modal events. Check the doc here: http://twitter.github.com/bootstrap/javascript.html#modals under Events.
$('#myModal').on('shown', function () {
// do something…
})
Here you go: http://jsfiddle.net/bws9N/
Edit: I don't really see a need for using that slide plugin here since you can get it to work anyway. But the main idea is here...
来源:https://stackoverflow.com/questions/13388002/autoscrolling-a-bootstrap-modal-on-modalshow