7

I have a Cocoa webview, with a web application in it. The web application has a fixed toolbar itself, and with the elastic scrolling, and the toolbar coming below the top, it looks bad. Is there a way to disable the elastic/rubber-band scrolling, or at least keep the toolbar from moving with the rest of the content? I can modify the web app as much as neede.

penguinrob
  • 1,431
  • 3
  • 17
  • 39
  • This is a hard-to-find question and answer, and hard to explain. I was searching on "cocoa webkit bounce effect" and didn't find this. Had to try another keyword "cocoa webkit scroll". I'm glad you posted it. I'd like to suggest removing osx-lion tag because it applies to all OSX, and also remove "in lion" from the question title too. It will make it easier for others to find this important question and answer. Also, the one-liner below from briangonzalez fixed me, rather than the answer you picked. It was also easier to do than kizu's answer. – Volomike Dec 14 '15 at 03:40

3 Answers3

23

If you're interested in doing it from the WebView and Cocoa perspective, you can also implement the finish load delegate, grab the scroll view, and disable elasticity:

- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
    NSScrollView *mainScrollView = sender.mainFrame.frameView.documentView.enclosingScrollView;
    [mainScrollView setVerticalScrollElasticity:NSScrollElasticityNone]; 
    [mainScrollView setHorizontalScrollElasticity:NSScrollElasticityNone];
}
Vervious
  • 5,559
  • 3
  • 38
  • 57
  • 1
    This does it from a Cocoa perspective, which is what the question asked. Using JavaScript/HTML can only easily be used on custom pages. – Oliver Cooper Nov 29 '12 at 21:31
  • Can you say more about why this specific delegate method? Why not, for example, in the resource loading delegate, or even in awakeFromNib? – Chris Page Mar 06 '14 at 02:03
5

Maybe this article would help you.

In short: disable overflow on HTML and BODY, add a wrapper with overflow:auto around all the page contents

kizu
  • 42,604
  • 4
  • 68
  • 95
  • NB: jQuery UI dialog boxes are always appended to the `body`, so you'd need to reparent them into your content div for this to work properly. – Alnitak Nov 03 '11 at 09:00
3

I know this comment likely won't be accepted, since there's already an answer.

However, there's an actual method you can call on your NSView (docs here):

[[[webView mainFrame] frameView] setAllowsScrolling:NO]; 
briangonzalez
  • 1,606
  • 16
  • 21
  • 1
    This prevents any scrolling, including no scrolling of content inside the WebView such as div's with scrollbars. The OP's question is just about turning off the 'bounce' effect WebViews have. Vervious' answer works correctly in this case. – asgeo1 Aug 30 '12 at 01:58
  • 2
    Came here from Google. Although this does not answer the question asked, it's what I came here looking for... +1 – Max Nov 15 '12 at 18:46
  • @asgeo1 That's not true. I ran this piece of code from my AppDelegate's applicationDidFinishLaunching, and have scrolling divs as well as iframes. They worked perfectly fine. This one line of code fixed the bounce effect, making my webkit app look more like an app and less like a web page. – Volomike Dec 14 '15 at 03:35