Swipeout - 图1

Swipeout (Swipeable List)

Swipeout is an extension of list view that allows you to swipe over list elements to reveal hidden menu with available actions, like swipe-to-delete.

Swipeout Layout

Let’s look on layout structure of swipeout element in your list views:

  1. <div class="list">
  2. <ul>
  3. <!-- Additional "swipeout" class on li -->
  4. <li class="swipeout">
  5. <!-- Usual list element wrapped with "swipeout-content" -->
  6. <div class="swipeout-content">
  7. <!-- Your list element here -->
  8. <div class="item-content">
  9. <div class="item-media">...</div>
  10. <div class="item-inner">...</div>
  11. </div>
  12. </div>
  13. <!-- Swipeout actions left -->
  14. <div class="swipeout-actions-left">
  15. <!-- Swipeout actions links/buttons -->
  16. <a href="#">Action 1</a>
  17. <a href="#">Action 2</a>
  18. </div>
  19. <!-- Swipeout actions right -->
  20. <div class="swipeout-actions-right">
  21. <!-- Swipeout actions links/buttons -->
  22. <a href="#" class="swipeout-close">Action 1</a>
  23. <a href="#" class="swipeout-delete">Delete</a>
  24. </div>
  25. </li>
  26. ...
  27. </ul>
  28. </div>

Where:

  • swipeout-content - wrapper for your list element. This container will move during swipe over the list item
  • swipeout-actions-left - container with left swipeout action buttons/links
  • swipeout-actions-right - container with right swipeout action buttons/links
  • swipeout-close - additional class on swipeout link that will close swipeout element when you click this link
  • swipeout-delete - additional class on swipeout link that will delete swipeout list item when you click this link

Note that **swipeout-content** and **swipeout-actions-left/right** should be direct children of

  • If you have only “item-content” you can simplify layout by adding “item-content” class to “swipeout-content”:

    1. <li class="swipeout">
    2. <div class="swipeout-content item-content">
    3. <div class="item-media">...</div>
    4. <div class="item-inner">...</div>
    5. </div>
    6. <div class="swipeout-actions-right">
    7. <a href="#">Action 1</a>
    8. <a href="#">Action 2</a>
    9. </div>
    10. </li>

    If you use link items the layout will be following:

    1. <li class="swipeout">
    2. <div class="swipeout-content">
    3. <a href="#" class="item-content item-link">
    4. <div class="item-media">...</div>
    5. <div class="item-inner">...</div>
    6. </a>
    7. </div>
    8. <div class="swipeout-actions-right">
    9. <a href="#">Action 1</a>
    10. <a href="#">Action 2</a>
    11. </div>
    12. </li>

    Swipe To Delete

    Framework7 supports this frequently used feature from the box without single line of JavaScript. All you need is to add **swipeout-delete** class to swipeout actions buttons:

    1. <li class="swipeout">
    2. <div class="swipeout-content item-content">
    3. <div class="item-media">...</div>
    4. <div class="item-inner">...</div>
    5. </div>
    6. <div class="swipeout-actions-right">
    7. <!-- Add this button and item will be deleted automatically -->
    8. <a href="#" class="swipeout-delete">Delete</a>
    9. </div>
    10. </li>

    It is also possible to call Confirm modal when user clicks on “Delete” button, and element will be removed only after confirmation. To make delete on confirmation you need to add additional **data-confirm** and **data-confirm-title** (optional) attributes to Delete link:

    1. <li class="swipeout">
    2. <div class="swipeout-content item-content">
    3. <div class="item-media">...</div>
    4. <div class="item-inner">...</div>
    5. </div>
    6. <div class="swipeout-actions-right">
    7. <!-- We add data-confirm and data-confirm-title attributes -->
    8. <a href="#" class="swipeout-delete" data-confirm="Are you sure want to delete this item?" data-confirm-title="Delete?">Delete</a>
    9. </div>
    10. </li>

    Overswipe

    Swipeouts also support “overswipe” actions that will be triggered automatically if you swipe actions too much. In this case we need to add **swipeout-overswipe** class to required actions button:

    1. <li class="swipeout">
    2. <div class="swipeout-content item-content">
    3. <div class="item-media">...</div>
    4. <div class="item-inner">...</div>
    5. </div>
    6. <div class="swipeout-actions-right">
    7. <a href="#">More</a>
    8. <a href="#" class="swipeout-delete swipeout-overswipe">Delete</a>
    9. </div>
    10. </div>
    11. </li>
    • overswipe can be used only on last button in right swipeout actions, and only on first button in left swipeout actions.

    • With overswipe, script will automatically trigger “click” event on overswipe button, so you need to add appropriate event listener to this button

    • Overswipe button will have additonal **swipeout-overswipe-active** class during overswipe which you can use for additional styling of such state

    1. <li class="swipeout">
    2. <div class="swipeout-content">
    3. <a href="#" class="item-content item-link">
    4. ...
    5. </a>
    6. </div>
    7. <div class="swipeout-actions-left">
    8. <a href="#" class="swipeout-overswipe bg-green reply">Reply</a>
    9. <a href="#" class="bg-blue forward">Forward</a>
    10. </div>
    11. <div class="swipeout-actions-right">
    12. <a href="#" class="mark bg-orange">Mark</a>
    13. <a href="#" class="swipeout-delete swipeout-overswipe">Delete</a>
    14. </div>
    15. </li>

    Swipeout App Methods

    Swipeouts also has rich JavaScript API that allows you to control swipeout elements. Let’s look on appropriate App’s methods:

    app.swipeout.open(el, side, callback) - reveal swipeout actions on specified element

    • el - HTMLElement or string (with CSS Selector) of list (
    • ) element with “swipeout” class. Required
    • side - string (could be “left” or “right”) swipeout actions to open. Should be specified if item has both left and right swipeout actions. Optional
    • callback - function - callback function will be executed after swipeout element completes its opening animation

    app.swipeout.close(el, callback) - close swipeout actions on specified element

    • el - HTMLElement or string (with CSS Selector) of list (
    • ) element with “swipeout” class. Required
    • callback - function - callback function will be executed after swipeout element completes its closing animation

    app.swipeout.delete(el, callback) - delete specified swipeout element

    • el - HTMLElement or string (with CSS Selector) of list (
    • ) element with “swipeout” class. Required
    • callback - function - callback function will be executed after swipeout element completes its delete animation right before it will be removed from DOM

    app.swipeout.el - property. Currently opened swipeout HTMLElement. Or undefined if there is no opened swipeout element

    Swipeout App Parameters

    It is possible to configure global swipeout behavior on app initialisation by passing swipeout related paremeters under swipeout property.

    ParameterTypeDefaultDescription
    noFollowbooleanfalseFallback option for potentially better performance on old/slow devices. If you enable it, then swipeout item will not follow your finger during touch, it will be automatically opened/closed on swipe left/right.
    removeElementsbooleantrueWhen disabled, then framework will not remove swipeout element from DOM on “swipeout-delete” click. Useful to enable if you use another library like Vue or React to manage (remove) swipeout items
    removeElementsWithTimeoutbooleanfalseWhen enabled, then framework will remove swipeout element from DOM on “swipeout-delete” click after specified delay
    removeElementsTimeoutnumber0Delay in ms to remove swipeout item if removeElementsWithTimeout is enabled.

    To change these parameters we need to pass them on app init under swipeout property, for example:

    1. var app = new Framework7({
    2. swipeout: {
    3. noFollow: true,
    4. removeElements: false
    5. }
    6. });

    Swipeout Events

    Swipeout will fire the following DOM events and events on app instance:

    DOM Events

    EventTargetDescription
    swipeoutSwipeout Element<li class=”swipeout”>Event will be triggered while you move swipeout element. event.detail contains current opening progress percentage
    swipeout:openSwipeout Element<li class=”swipeout”>Event will be triggered when swipeout element starts its opening animation
    swipeout:openedSwipeout Element<li class=”swipeout”>Event will be triggered after swipeout element completes its opening animation
    swipeout:closeSwipeout Element<li class=”swipeout”>Event will be triggered when swipeout element starts its closing animation
    swipeout:closedSwipeout Element<li class=”swipeout”>Event will be triggered after swipeout element completes its closing animation
    swipeout:deleteSwipeout Element<li class=”swipeout”>Event will be triggered after swipeout element starts its delete animation
    swipeout:deletedSwipeout Element<li class=”swipeout”>Event will be triggered after swipeout element completes its delete animation right before it will be removed from DOM
    swipeout:overswipeenterSwipeout Element<li class=”swipeout”>Event will be triggered when overswipe enabled
    swipeout:overswipeexitSwipeout Element<li class=”swipeout”>Event will be triggered when overswipe disabled

    App Instance Events

    Sortable instance emit events on app instance.

    EventTargetArgumentsDescription
    swipeoutappprogressEvent will be triggered while you move swipeout element
    swipeoutOpenappswipeoutElEvent will be triggered when swipeout element starts its opening animation
    swipeoutOpenedappswipeoutElEvent will be triggered after swipeout element completes its opening animation
    swipeoutCloseappswipeoutElEvent will be triggered when swipeout element starts its closing animation
    swipeoutClosedappswipeoutElEvent will be triggered after swipeout element completes its closing animation
    swipeoutDeleteappswipeoutElEvent will be triggered after swipeout element starts its delete animation
    swipeoutDeletedappswipeoutElEvent will be triggered after swipeout element completes its delete animation right before it will be removed from DOM
    swipeoutOverswipeEnterappswipeoutElEvent will be triggered when overswipe enabled
    swipeoutOverswipeExitappswipeoutElEvent will be triggered when overswipe disabled

    Examples

    1. var app = new Framework7();
    2. var $$ = Dom7;

    Swipe to delete with confirm modal

    1. <div class="list">
    2. <ul>
    3. <li class="swipeout">
    4. <div class="item-content swipeout-content">
    5. <div class="item-media"><i class="icon icon-f7"></i>
    6. </div>
    7. <div class="item-inner">
    8. <div class="item-title">Swipe left on me please</div>
    9. </div>
    10. </div>
    11. <div class="swipeout-actions-right">
    12. <a href="#" data-confirm="Are you sure you want to delete this item?" class="swipeout-delete">Delete</a>
    13. </div>
    14. </li>
    15. <li class="swipeout">
    16. <div class="item-content swipeout-content">
    17. <div class="item-media"> <i class="icon icon-f7"></i>
    18. </div>
    19. <div class="item-inner">
    20. <div class="item-title">Swipe left on me too</div>
    21. </div>
    22. </div>
    23. <div class="swipeout-actions-right">
    24. <a href="#" data-confirm="Are you sure you want to delete this item?" class="swipeout-delete">Delete</a>
    25. </div>
    26. </li>
    27. <li>
    28. <div class="item-content">
    29. <div class="item-media">
    30. <i class="icon icon-f7"></i>
    31. </div>
    32. <div class="item-inner">
    33. <div class="item-title">I am not removable</div>
    34. </div>
    35. </div>
    36. </li>
    37. </ul>
    38. </div>

    Swipe to delete without confirm

    1. <div class="list">
    2. <ul>
    3. <li class="swipeout">
    4. <div class="item-content swipeout-content">
    5. <div class="item-inner">
    6. <div class="item-title">Swipe left on me please</div>
    7. </div>
    8. </div>
    9. <div class="swipeout-actions-right">
    10. <a href="#" class="swipeout-delete">Delete</a>
    11. </div>
    12. </li>
    13. <li class="swipeout">
    14. <div class="item-content swipeout-content">
    15. <div class="item-inner">
    16. <div class="item-title">Swipe left on me too</div>
    17. </div>
    18. </div>
    19. <div class="swipeout-actions-right">
    20. <a href="#" class="swipeout-delete">Delete</a>
    21. </div>
    22. </li>
    23. <li>
    24. <div class="item-content">
    25. <div class="item-inner">
    26. <div class="item-title">I am not removable</div>
    27. </div>
    28. </div>
    29. </li>
    30. </ul>
    31. </div>

    Swipe for actions

    1. <div class="list">
    2. <ul>
    3. <li class="swipeout">
    4. <div class="item-content swipeout-content">
    5. <div class="item-media">
    6. <i class="icon icon-f7"></i>
    7. </div>
    8. <div class="item-inner">
    9. <div class="item-title">Swipe left on me please</div>
    10. </div>
    11. </div>
    12. <div class="swipeout-actions-right">
    13. <a href="#" class="open-more-actions">More</a>
    14. <a href="#" class="swipeout-delete">Delete</a>
    15. </div>
    16. </li>
    17. <li class="swipeout">
    18. <div class="item-content swipeout-content">
    19. <div class="item-media">
    20. <i class="icon icon-f7"></i>
    21. </div>
    22. <div class="item-inner">
    23. <div class="item-title">Swipe left on me too</div>
    24. </div>
    25. </div>
    26. <div class="swipeout-actions-right">
    27. <a href="#" class="open-more-actions">More</a>
    28. <a href="#" class="swipeout-delete">Delete</a>
    29. </div>
    30. </li>
    31. <li class="swipeout">
    32. <div class="item-content swipeout-content">
    33. <div class="item-media">
    34. <i class="icon icon-f7"></i>
    35. </div>
    36. <div class="item-inner">
    37. <div class="item-title">You can't delete me</div>
    38. </div>
    39. </div>
    40. <div class="swipeout-actions-right">
    41. <a href="#" class="open-more-actions">More</a>
    42. </div>
    43. </li>
    44. </ul>
    45. </div>
    1. var moreActions = app.actions.create({
    2. buttons: [
    3. [
    4. {
    5. text: 'Here comes some optional description or warning for actions below',
    6. label: true,
    7. },
    8. {
    9. text: 'Action 1',
    10. },
    11. {
    12. text: 'Action 2',
    13. },
    14. ],
    15. [
    16. {
    17. text: 'Cancel',
    18. bold: true,
    19. }
    20. ]
    21. ],
    22. });
    23. $$('.open-more-actions').on('click', function () {
    24. moreActions.open();
    25. });

    With callback on remove

    1. <div class="list">
    2. <ul>
    3. <li class="swipeout deleted-callback">
    4. <div class="item-content swipeout-content">
    5. <div class="item-inner">
    6. <div class="item-title">Swipe left on me please</div>
    7. </div>
    8. </div>
    9. <div class="swipeout-actions-right">
    10. <a href="#" class="swipeout-delete">Delete</a>
    11. </div>
    12. </li>
    13. <li class="swipeout deleted-callback">
    14. <div class="item-content swipeout-content">
    15. <div class="item-inner">
    16. <div class="item-title">Swipe left on me too</div>
    17. </div>
    18. </div>
    19. <div class="swipeout-actions-right">
    20. <a href="#" class="swipeout-delete">Delete</a>
    21. </div>
    22. </li>
    23. <li>
    24. <div class="item-content">
    25. <div class="item-inner">
    26. <div class="item-title">I am not removable</div>
    27. </div>
    28. </div>
    29. </li>
    30. </ul>
    31. </div>
    1. $$('.deleted-callback').on('swipeout:deleted', function () {
    2. app.dialog.alert('Thanks, item removed!');
    3. });

    With actions on left side (swipe to right)

    1. <div class="list">
    2. <ul>
    3. <li class="swipeout">
    4. <div class="item-content swipeout-content">
    5. <div class="item-media">
    6. <i class="icon icon-f7"></i>
    7. </div>
    8. <div class="item-inner">
    9. <div class="item-title">Swipe right on me please</div>
    10. </div>
    11. </div>
    12. <div class="swipeout-actions-left">
    13. <a href="#" class="color-green alert-reply">Reply</a>
    14. <a href="#" class="color-blue alert-forward">Forward</a>
    15. </div>
    16. </li>
    17. <li class="swipeout">
    18. <div class="item-content swipeout-content">
    19. <div class="item-media">
    20. <i class="icon icon-f7"></i>
    21. </div>
    22. <div class="item-inner">
    23. <div class="item-title">Swipe right on me too</div>
    24. </div>
    25. </div>
    26. <div class="swipeout-actions-left">
    27. <a href="#" class="color-green alert-reply">Reply</a>
    28. <a href="#" class="color-blue alert-forward">Forward</a>
    29. </div>
    30. </li>
    31. </ul>
    32. </div>
    1. $$('.alert-reply').on('click', function () {
    2. app.dialog.alert('Reply');
    3. });
    4. $$('.alert-forward').on('click', function () {
    5. app.dialog.alert('Forward');
    6. });

    On both sides with overswipes

    1. <div class="list media-list">
    2. <ul>
    3. <li class="swipeout">
    4. <div class="swipeout-content">
    5. <a href="#" class="item-link item-content">
    6. <div class="item-inner">
    7. <div class="item-title-row">
    8. <div class="item-title">Facebook</div>
    9. <div class="item-after">17:14</div>
    10. </div>
    11. <div class="item-subtitle">New messages from John Doe</div>
    12. <div class="item-text">
    13. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus.
    14. </div>
    15. </div>
    16. </a>
    17. </div>
    18. <div class="swipeout-actions-left">
    19. <a href="#" class="color-green swipeout-overswipe alert-reply">Reply</a>
    20. <a href="#" class="color-blue alert-forward">Forward</a>
    21. </div>
    22. <div class="swipeout-actions-right">
    23. <a href="#" class="open-more-actions">More</a>
    24. <a href="#" class="color-orange alert-mark">Mark</a>
    25. <a href="#" data-confirm="Are you sure you want to delete this item?" class="swipeout-delete swipeout-overswipe">Delete</a>
    26. </div>
    27. </li>
    28. ...
    29. </ul>
    30. </div>