Progressbar

    In addition to Preloader Framework7 also comes with fancy animated determinate and infinite/indeterminate progressbars to indicate activity.

    When progressbar is determinate it indicates how long an operation will take when the percentage complete is detectable.

    Let’s look at layout of determinate progressbar:

    Where data-progress=”20” - current progress (in percents). Note that this data attribute sets progress only on page load. If you need to change it later it should be done via API.

    Infinite Progressbar

    Let’s look at layout of infinite progressbar:

    Progressbar supports all default colors. So to change its color just add color-[color] class to preloader element.

    Progressbar API

    Progressbar comes with API that allows you to control Progressbar’s progress, show and hide it. Let’s look on appropriate App’s properties and methods:

    app.progressbar.set(el, progress, duration) - set progress for Determinate Progressbar.

    • el - string or HTMLElement. Progressbar element or element containing progressbar element. If string - CSS selector of such element.
    • progress - number. Progress in percents (from 0 to 100)
    • speed - number. Transition duration of progress change animation (in ms)
    • This method returns Progressbar HTMLElement
    • progress - number. Progress in percents (from 0 to 100)
    • speed - number. Transition duration of progress change animation (in ms)
    • This method returns Progressbar HTMLElement

    app.progressbar.show(el, progress, color) - create and show or just show (if already presented) progressbar.

    • el - string or HTMLElement. Progressbar element container or element containing progressbar element. If string - CSS selector of such element. Optional
    • progress - number. Progress in percents (from 0 to 100). Optional
    • color - string. Color of progressbar, for example “white”, “red”, etc. from available color themes. Optional
    • This method returns Progressbar HTMLElement

    All arguments here are optional:

    • If you omit el argument, it will look for (or create) progressbar element under app root
    • If you omit progress, it will show/create infinite progressbar
    • If you omit all arguments, then it will show/create infinite progressbar under the app root with default color

    app.progressbar.hide(el) - hide Progressbar.

    • el - string or HTMLElement. Progressbar element container or element containing progressbar element. If string - CSS selector of such element. If not specified then it will look for such element under the app root element.

    Below is the list of related (CSS custom properties).

    1. :root {
    2. /*
    3. --f7-progressbar-progress-color: var(--f7-theme-color);
    4. */
    5. }
    6. .ios {
    7. --f7-progressbar-bg-color: #b6b6b6;
    8. --f7-progressbar-height: 2px;
    9. --f7-progressbar-border-radius: 2px;
    10. }
    11. .md {
    12. /*
    13. --f7-progressbar-bg-color: rgba(var(--f7-theme-color-rgb), 0.5);
    14. */
    15. --f7-progressbar-height: 4px;
    16. --f7-progressbar-border-radius: 0px;
    17. }
    18. .aurora {
    19. --f7-progressbar-bg-color: #dbdbdb;
    20. --f7-progressbar-height: 6px;
    21. --f7-progressbar-border-radius: 3px;
    22. }
    23. .aurora .theme-dark,
    24. .aurora.theme-dark {
    25. }

    Examples

    1. <div class="block-title">Infinite Progress Bar</div>
    2. <div class="block block-strong">
    3. <p>Inline infinite progress bar</p>
    4. <p>
    5. <span class="progressbar-infinite"></span>
    6. </p>
    7. <p>Multi-color infinite progress bar</p>
    8. <p>
    9. <span class="progressbar-infinite color-multi"></span>
    10. </p>
    11. <p>Overlay with infinite progress bar on top of the app</p>
    12. <p id="demo-infinite-container"></p>
    13. <p>
    14. <a href="#" class="button button-raised show-infinite">Start Loading</a>
    15. </p>
    16. </div>
    17. <div>
    18. <p>Overlay with infinite multi-color progress bar on top of the app</p>
    19. <p>
    20. <a href="#" class="button button-raised show-infinite-root">Start Loading</a>
    21. </p>
    22. </div>
    23. </div>
    1. var app = new Framework7();
    2. var $$ = Dom7;
    3. // Set progress on inline progressbar
    4. $$('.set-inline-progress').on('click', function (e) {
    5. var progress = $$(this).attr('data-progress');
    6. app.progressbar.set('#demo-inline-progressbar', progress);
    7. });
    8. // Function show determinate progressbar and emulate loading
    9. determinateLoading = false;
    10. function showDeterminate(inline) {
    11. determinateLoading = true;
    12. var progressBarEl;
    13. if (inline) {
    14. // inline progressbar
    15. progressBarEl = app.progressbar.show('#demo-determinate-container', 0);
    16. } else {
    17. // root progressbar
    18. }
    19. var progress = 0;
    20. function simulateLoading() {
    21. setTimeout(function () {
    22. progress += Math.random() * 20;
    23. app.progressbar.set(progressBarEl, progress);
    24. if (progressBefore < 100) {
    25. simulateLoading(); //keep "loading"
    26. }
    27. else {
    28. determinateLoading = false;
    29. app.progressbar.hide(progressBarEl); //hide
    30. }
    31. }, Math.random() * 200 + 200);
    32. }
    33. simulateLoading();
    34. }
    35. // show inline determinate progressbar
    36. $$('.show-determinate').on('click', function (e) {
    37. showDeterminate(true);
    38. });
    39. // show root determinate progressbar
    40. $$('.show-determinate-root').on('click', function (e) {
    41. showDeterminate(false);
    42. });
    43. var infiniteLoading = false;
    44. // show inline infinite progressbar
    45. $$('.show-infinite').on('click', function () {
    46. app.progressbar.show(app.theme === 'md' ? 'yellow' : 'blue');
    47. setTimeout(function () {
    48. infiniteLoading = false;
    49. app.progressbar.hide();
    50. }, 3000);
    51. });
    52. // show root infinite progressbar
    53. $$('.show-infinite-root').on('click', function () {
    54. app.progressbar.show('multi');
    55. setTimeout(function () {
    56. infiniteLoading = false;
    57. app.progressbar.hide();
    58. });