[英]Scrolling a div vertically using Javascript in MVC3
I am an application development intern. 我是应用程序开发实习生。 I'm making an application using ASP.NET MVC3 that displays in boxes various projects the company using it is working on.
我正在使用ASP.NET MVC3制作应用程序,该应用程序在框中显示公司正在使用的各种项目。 These boxes are created in a table using a foreach loop.
这些框是使用foreach循环在表中创建的。
<div class= "row">
@foreach (var item in Model)
{
@Html.Action("Client", new { controller = "Dashboard", Client = item })
}
</div>
I want these boxes to automatically scroll down if there is an overflow. 如果溢出,我希望这些框自动向下滚动。 This appears to be the function that I would like to use:
这似乎是我要使用的功能:
function pageScroll() {
window.scrollBy(0,50); // horizontal and vertical scroll increments
scrolldelay = setTimeout('pageScroll()',100); // scrolls every 100 milliseconds
}
How do I apply this function to the boxes being created in the foreach loop? 如何将此功能应用于在foreach循环中创建的框?
EDIT: Using Timothy-Strimple's advice, I used a Jquery plugin called scrollTo() to create this: 编辑:根据Timothy-Strimple的建议,我使用了一个名为scrollTo()的Jquery插件来创建此插件:
for (d = 0; d < 52; d) {
$(".dashboard-well").scrollTo('100%', 10000).delay(2000);
$(".dashboard-well").scrollTo('0%', 10000).delay(2000);
d++;
}
Now the div I was looking at, when overflowed, will scroll down, then back up 5x. 现在,当我看到的div溢出时,它将向下滚动,然后向上滚动5倍。
I'm not quite sure I understand what you're trying to do. 我不太确定我了解您要做什么。 If you want to set a div to overflow: scroll, and then scroll to the bottom of it, that's pretty straight forward with jQuery.
如果要将div设置为溢出,请滚动:滚动,然后滚动到它的底部,这对于jQuery非常简单。 I have done something like that on my sample chat app where the page will scroll to the bottom every time there is a new message.
我在示例聊天应用程序上做了类似的操作,每当有新消息出现时,页面都会滚动到底部。 It looks like this:
看起来像这样:
$('#messages').scrollTop($('#messages')[0].scrollHeight);
So what you can do is after you've created all of your rows, set scrollTop on the element like I have done above, and set it to the scrollHeight and that will put the scrollbar at the bottom of the section. 因此,您可以做的是在创建所有行之后,像上面一样在元素上设置scrollTop,然后将其设置为scrollHeight,这会将滚动条放在该部分的底部。
If that is not what you are asking, please update your question or post a comment so I can update my answer. 如果这不是您要的内容,请更新您的问题或发表评论,以便我更新我的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.