4

I want to disable the horizontal scroll elasticity of an NKWebView instance in my app for macOS.

I know we can control elasticity of an NSScrollView with verticalScrollElasticity or horizontalScrollElasticity properties. But it seems to be impossible to obtain scrollView from new WKWebView on macOS, although WKWebView for iOS has a scrollView property that holds UIScrollView. I also cannot find a proper property in WKWebView to control it.

I found a Q&A: Disable rubber-band scrolling for webview in lion in SO for the old WebView. But it doesn't work anymore with a new WKWebView since new WKWebView doesn't have a mainFrame property.

1024jp
  • 2,058
  • 1
  • 16
  • 25
  • There's a similar question with an interesting response at https://stackoverflow.com/questions/39929552/disable-bounce-scrolling-for-wkwebview-in-macos – jeff-h Sep 23 '19 at 08:40

1 Answers1

0

This helped me for vertical case (at html/css level): https://stackoverflow.com/a/28411556/307093

I think you should try overflow-x css property. In case you do not control what the page displays you can execute javascript from Objective-C/Swift in the page after it is loaded, which will change the body page attributes, like document.body.style.overflowX = 'hidden', probably you will need to specify document.body.style.width to something meaningful/concrete too.

dev_null
  • 1,907
  • 1
  • 16
  • 25