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

Enhance front page screenshot navigation with swiping #400

Open
garrett opened this issue Apr 15, 2021 · 1 comment
Open

Enhance front page screenshot navigation with swiping #400

garrett opened this issue Apr 15, 2021 · 1 comment
Assignees

Comments

@garrett
Copy link
Member

garrett commented Apr 15, 2021

As a follow-up to #398, we should have swiping to get from one screenshot to the next.

Previously, I had a commit with that, but reverted it, as it didn't have animation.

A better approach might be to add all screenshots in an element that's ((# of screenshots + padding) × screenwidth), have it longer then the page, constrain it to page width, make sure it scrolls, and add scroll stops.

This would:

  1. reduce the amount of JavaScript necessary
  2. use accelerated rendering (including GPU acceleration)
  3. feel natural, as it would use the same scroll swiping as a native platform
  4. be a testbed to see how CSS scroll stops work, as they could be useful in parts of Cockpit too
@garrett garrett self-assigned this Apr 15, 2021
@garrett
Copy link
Member Author

garrett commented Apr 15, 2021

For reference, the deleted code that handled swiping via touch was:

  $(document).on('touchstart', function(ev){
    if (!previewIsVisible()) { return; }
    touchX = ev.touches[0].clientX;
    touchY = ev.touches[0].clientY;
  }).on('touchmove', function(ev){
    if (!previewIsVisible()) { return; }
    if (!touchX || !touchY) { return; }

    var action;
    var swipeThreshold = 10;
    var distanceX = touchX - ev.touches[0].clientX;
    var distanceY = touchY - ev.touches[0].clientY;

    // Choose swipe distance based on greater direction
    var distance = (Math.abs(distanceX) > Math.abs(distanceY)) ? distanceX : distanceY;

    // Exit if threshold is not met
    if (Math.abs(distance) < swipeThreshold) {
      return;
    }

    // Check direction (either up/down, left/right) based on positive/negative
    action = (distance > 0) ? 'next' : 'prev';
    switchPreview(action);
  });

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