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

Javascript workaround for slow scrolling with smooth scrolling in firefox - Stack Overflow

programmeradmin3浏览0评论

I am a developer for a web application. In this application there is a certain scenario where there are multiple position:fixed elements, and canvases and a overflow:scroll element. In this scenario, scrolling is super slow on firefox when smooth scrolling is enabled.

From the user's perspective the solution is simply to disable smooth scrolling. However, as a developer I can't ensure that the user has done this.

Is there anywhere that I can tell firefox to not to use smooth scrolling for my website from javascript (or html)? Or is there any other known workaround for this?

I am a developer for a web application. In this application there is a certain scenario where there are multiple position:fixed elements, and canvases and a overflow:scroll element. In this scenario, scrolling is super slow on firefox when smooth scrolling is enabled.

From the user's perspective the solution is simply to disable smooth scrolling. However, as a developer I can't ensure that the user has done this.

Is there anywhere that I can tell firefox to not to use smooth scrolling for my website from javascript (or html)? Or is there any other known workaround for this?

Share Improve this question asked Jul 16, 2014 at 16:43 ThayneThayne 7,0523 gold badges46 silver badges73 bronze badges 6
  • 1 try cutting down on css that slows scrolling, in particular rgba colors, non-1 opacities, and box-shadows. – dandavis Commented Jul 16, 2014 at 16:48
  • That isn't really an option for me. – Thayne Commented Jul 21, 2014 at 19:03
  • simply you don't want smooth scrolling on firefox right ? – Ismail Farooq Commented Jul 15, 2016 at 10:04
  • If you want to get into a client's browser and control it, develop a web extension. MDN WebExtensions – zer00ne Commented Jul 17, 2016 at 7:28
  • Have you tried to use any scrollbar library such as github./gromo/jquery.scrollbar or ayeressian.github.io/flexible-scrollbar ? – Ara Yeressian Commented Jul 22, 2016 at 8:00
 |  Show 1 more ment

3 Answers 3

Reset to default 4 +125

I do understand that your question basically is how to disable smooth scrolling. however I will answer you a little differently to get this working.

Why different?

Even if you can detect smooth scrolling of users, you cannot force the user to disable it. In other words, you are trying to cover the problem instead of solving it. so lets solve it!

Intro: pixels-to-screen pipeline

On each frame the browser does the following steps to render the page on screen.

  • JavaScript. Typically JavaScript is used to handle work that will result in visual changes, whether it’s jQuery’s animate function, sorting a data set, or adding DOM elements to the page. It doesn’t have to be JavaScript that triggers a visual change, though: CSS Animations, Transitions, and the Web Animations API are also monly used.

  • Style calculations. This is the process of figuring out which CSS rules apply to which elements based on matching selectors, e.g. .headline or .nav > .nav__item. From there, once rules are known, they are applied and the final styles for each element are calculated.

  • Layout. Once the browser knows which rules apply to an element it can begin to calculate how much space it takes up and where it is on screen. The web’s layout model means that one element can affect others, e.g. the width of the element typically affects its children’s widths and so on all the way up and down the tree, so the process can be quite involved for the browser.

  • Paint. Painting is the process of filling in pixels. It involves drawing out text, colors, images, borders, and shadows, essentially every visual part of the elements. The drawing is typically done onto multiple surfaces, often called layers.

  • Compositing. Since the parts of the page were drawn into potentially multiple layers they need to be drawn to the screen in the correct order so that the page renders correctly. This is especially important for elements that overlap another, since a mistake could result in one element appearing over the top of another incorrectly.

details and source: https://developers.google./web/fundamentals/performance/rendering/?hl=en

Step 1:

First step is to remove render costly css properties. You might not be able to remove alot, however you can replace rgba(255,255,255,1); with #fff which removes the alpha layer.

check this for more details: https://csstriggers./ some properties do not need to do a layout or a paint and there are less heavy than others.

Step 2:

Check for forced synchronous layout triggers. These happen when you force the browser to do a layout while its in the javascript step, then return to javascript, instead of walking smoothly along the pipeline on each frame. to do this, avoid getting layout attributes and setting them directly afterwards in a loop for example.

here is a list of what causes sync layout: https://gist.github./paulirish/5d52fb081b3570c81e3a

read more: https://developers.google./web/tools/chrome-devtools/profile/rendering-tools/forced-synchronous-layouts?hl=en

Step 3:

Move ponents on the page that need to be repainted regularly into new layers.

The browser needs to repaint every time you scroll or an animation is playing. to avoid a full page repaint and only repaint the part that is changing, move that part (ex parallax, navigation, animation) to a new layer on the browser (think about it like photoshop layers)

to do so use the will-change css property to tell the browser to move it to a new layer, and use transform: translateZ(0); if you want to force the broswer to move it.

Have you tried adding

backface-visibility: hidden;

to you fixed position elements?

I would rather fix the source of the problem. Often there is one small detail that creates a giant bottleneck and that is easy to fix with the change of one line of code or something. Note that you most probably won't need to reduce the "good looks" of the app at all; it's just a matter of avoiding the small but devastating-for-performance details of the browser's layout engine.

I'll make a guess and say that something on you web app is causing very large repaints and/or frequent reflows. Check for things like usage of offsetTop and position: fixed. Also using requestAnimationFrame instead of updating for every scroll event is something worth looking at. Here's a good guide on both finding and fixing scrolling performance problems.

Use inspect element to try and get a handle on the specific cause. Also, if you've not installed FireBug, install it and use it instead of the default inspect element. This will give you more code details and allow you to step through the script to find the problem. There also plugins for FireBug for various frameworks, which can aid the diagnostics if your using one of those frameworks.

We can make assumptions about the cause or e up with shotgun solutions; but, only you can diagnose your code to find the specifics.

发布评论

评论列表(0)

  1. 暂无评论