Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jerky scrolling behavior on Firefox and mobile devices #152

Closed
lpellegr opened this issue Mar 8, 2018 · 5 comments
Closed

Jerky scrolling behavior on Firefox and mobile devices #152

lpellegr opened this issue Mar 8, 2018 · 5 comments

Comments

@lpellegr
Copy link

lpellegr commented Mar 8, 2018

When allowOutsideScroll is true and you tap on the element to display its dropdown-content and then scroll, the dropdown-content take a few milliseconds to realign, thus making the movement jerky.

I am able to reproduce the issue with iron-dropdown version 2.2.0 on Firefox but also Chrome on Android. That's really annoying, especially if the drop-down is kept open on a page for demo purposes. The behavior is too jerky.

The iron-dropdown demo page is a good place to reproduce the issue. Open it, move to "Scroll actions" example and click on "Refit on scroll" button. Then, scroll down and up several times.

Another example in a landing page:

https://noticeable.io

Look at the widget in the center when you scroll down and up.

This issue seems there since months. Any workarounds or ideas about the cause of this jerky movement on scrolling?

@lpellegr
Copy link
Author

lpellegr commented Mar 8, 2018

The following patch fixes the scrolling issue but breaks the positioning:

childdotorg@eba9a58

At first sight, the issue seems related to the fixed position of the host element.

@lpellegr
Copy link
Author

lpellegr commented Mar 9, 2018

@valdrinkoshi Any thoughts?

@valdrinkoshi
Copy link
Member

valdrinkoshi commented Mar 9, 2018

The reason why is janky is because iron-dropdown is position: fixed and recomputes the position where it should be at each frame through a raf.
It is position: fixed because its positionTarget might be different from the offsetParent, and as a consequence we need to listen for scroll events and update positioning - scroll events are received after the fact happened, and on top of that we "deRAF" the position update (aka we do requestAnimationFrame(refit).

One possible improvement would be to set position: absolute if positionTarget === offsetParent (to be done in iron-fit-behavior), which would handle cases like this:

<style>
  .container { position: relative; }
</style>
<div class="container">
  <iron-dropdown allow-outside-scroll>

Would you be willing to give it a try? PR welcome!

A solution that works with current implementation is unset vertical/horizontal-align and position: absolute on the dropdown:

<style>
  .container { position: relative; }
  .container iron-dropdown {
    position: absolute;
    left: 0; /* vertical-align="left" */
    top: 0; /* vertical-align="top" */
  }
</style>
<div class="container">
  <iron-dropdown allow-outside-scroll horizontal-align="" vertical-align="">

@valdrinkoshi
Copy link
Member

valdrinkoshi commented Mar 9, 2018

In terms of UX, <iron-dropdown> was conceived to behave as the native <select>: it either locks scrolling outside or closes on scroll outside (both supported through the scrollAction property.
allowOutsideScroll is something in between, for which one would be better off simply using position: absolute and do the actual positioning themselves:

<div style="position:relative">
  <div style="position: absolute; top: 0; left: 0">

@lpellegr
Copy link
Author

lpellegr commented Mar 9, 2018

@valdrinkoshi Thanks a lot for your explanations. I was able to understand and fix the behavior. If I find the time, I will look for the PR you have suggested.

@lpellegr lpellegr closed this as completed Mar 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants