最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disable the body scroll, but keep it on individual div elements which are greater in height than the browser - Stac

programmeradmin5浏览0评论

I have searched everywhere and have yet to get a solution. Okay heres the deal, I have a one page website which has several div elements underneath each other, sort of acting like individual pages I guess. What I want to achieve is to disable the scrolling of the actual web page all together, yet keeping the scroll of the active div in play if it goes below the web browser. To get to each other section of the page is simple done by using anchor links on the header.

I have searched everywhere and have yet to get a solution. Okay heres the deal, I have a one page website which has several div elements underneath each other, sort of acting like individual pages I guess. What I want to achieve is to disable the scrolling of the actual web page all together, yet keeping the scroll of the active div in play if it goes below the web browser. To get to each other section of the page is simple done by using anchor links on the header.

Share Improve this question asked Oct 24, 2012 at 21:39 Muhammed BhikhaMuhammed Bhikha 5,0199 gold badges37 silver badges47 bronze badges 1
  • What is the question? Can we see some sample code? – Jason Commented Oct 24, 2012 at 21:50
Add a ment  | 

3 Answers 3

Reset to default 4

I'm not exactly sure what you're looking for, but I think you want a div to be scrollable, but not the actual document. You can do this by absolutely positioning the div on the screen with a fixed height and set the overflow to auto. I've done this using the following CSS code:

#scrollable {
    position: absolute;
    top: 10px;
    right: 10px;
    bottom: 10px;
    left: 10px;
    overflow: auto;
}​

See an example: http://jsfiddle/rustyjeans/rgzBE/

Have you tried with overflow-x:hidden;

turns out its quite simple. CSS

body{
 overflow:hidden;
}

#div_you_need_scrolling{
 overflow:auto;
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论