开发者

How to make a div not scroll off the page using jquery

开发者 https://www.devze.com 2023-02-06 20:21 出处:网络
Basically I have a structure which is something like this: <body> <div> main content </div>

Basically I have a structure which is something like this:

<body>
   <div> main content </div>
   <div> toolbar </div>
   <div> results </div>

When scrolling down, I want the "main content" to disappear off the screen. The 'toolbar' to stay flush with the top of the page, and the 'results' to scroll, disappearing into the 'toolbar' as they scroll.

EDIT: the toolbar starts off in the middle of the screen. I want it to scroll to the top, but then no further, but 开发者_开发技巧the rest of the page (below) keeps scrolling.

I found this tutorial http://www.wduffy.co.uk/blog/keep-element-in-view-while-scrolling-using-jquery/

But this is slightly different. In the example above, although the toolbar stays near the top, it prevents the results from being scrolled.


I would have position:fixed; for the toolbar. That way it will stay fixed in the view.

<body>
   <div> main content </div>
   <div style="position:fixed;"> toolbar </div>
   <div> results </div>


Are you using ASP.NET AJAX? If so you can use something like the Always visible control:

http://www.asp.net/ajaxlibrary/HOW%20TO%20Use%20the%20AlwaysVisible%20Control.ashx

If not I believe there are some jQuery remakes of it, I believe this one might work as well:

http://www.west-wind.com/WebLog/posts/388213.aspx


$(".myDivClass").css("overflow", "hidden");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号