Autoscrolling a bootstrap modal on modal('show')

此生再无相见时 提交于 2019-12-11 00:30:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!