如何滚动到使用jQuery的模式内的元素? [英] How to scroll to an element within a modal using jquery?

查看:78
本文介绍了如何滚动到使用jQuery的模式内的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个打开的模式,我将元素逐行插入。每一行都有它自己的ID标签。目前,当列表比模态窗口更大时,文本会隐藏在模态窗口的底部。您可以手动使用滚动条,但我希望文本在打印时在模式窗口中向上滚动。



我玩过下面的代码,但只是滚动模式后面的网页。我也尝试用模式元素替换'html,body'无效。
$ b

  $('html,body')。 animate({scrollTop:$('#Element')。offset()。top},500); 

我确定我关门了。任何建议?



谢谢 解决方案

html和body的动画方法。

  $('html,body')。animate(...); 

如果您想滚动模态窗口,则必须调用该元素上的animate方法。 / p>

  $('#modal')。animate(...); 

其中 #modal 是包含元素你已经创建。



编辑:



我看到你试图在模态上调用动画。
这里是一个小提琴,可以在单击按钮时滚动模式中的元素。



也在代码中,在 #Element 之后有一个结尾括号,导致脚本错误: ... scrollTop:$('#Element'])...


I have an opened modal that I insert elements into line by line. Each line has it's own ID tag. Currently as the the list grows bigger than the modal window the text just gets hidden at the bottom of the modal window. You can manually use the scroll bar but I would like the text to scroll up in the modal window as they printed.

I have played around with the following code but that just scrolls the webpage behind the modal. I have also tried replacing 'html, body' with modal elements to no avail.

$('html, body').animate({ scrollTop: $('#Element').offset().top }, 500);

I'm sure I close. Any suggestions?

thanks

解决方案

It looks like you are calling the animate method on html and body.

$('html, body').animate(...);

If you want to scroll the modals window you have to call the animate method on that element instead.

$('#modal').animate(...);

Where #modal is the element containing the elements you've created.

edit:

I see that you tried to call animate on the modal. Here is a fiddle that scrolls elements in a modal when you click the button.

also in the code you have a closing bracket after #Element which is causing the script to error: ...scrollTop: $('#Element'])...

这篇关于如何滚动到使用jQuery的模式内的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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