在模态('show')上自动滚动bootstrap模态 [英] Autoscrolling a bootstrap modal on modal('show')

查看:89
本文介绍了在模态('show')上自动滚动bootstrap模态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于评论的bootstrap模式。评论表格附在评论列表的底部。
我希望这个模态滚动到列表的底部,当它打开时,如果有超过2或3条注释。我已安装此幻灯片插件

http://jesseprice.com/ jquery-slide-to-plugin /

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/

理想情况下,我希望能够使用该插件。我已经设置了一个小提琴我当前的想法:
http://jsfiddle.net/D2RLR/ 3275 /

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/

这是我目前的jQuery

Here is my current jQuery

    $('.slideto').slideto({
    target : '.new-comment-entry',
    speed  : 'slow'
});

我已经在regualr浏览器窗口中使用它,但它不会附加到模态。

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 ;)

推荐答案

是。因为如果没有显示该模态,你无法告诉你的模态体滚动...你需要使用某种回调函数。 Twitter Bootstrap为您提供模态事件。请查看此处的文档: http://twitter.github.com/bootstrap/javascript.html# 活动下的模态

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…
})

在这里: http://jsfiddle.net/bws9N/

编辑:我真的不需要在这里使用幻灯片插件,因为无论如何你都可以使用它。但主要的想法是......

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...

这篇关于在模态('show')上自动滚动bootstrap模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆