Preloader - 图1

Preloader

Framework7 has a nice preloader indicator. Preloader is made with SVG and animated with CSS so it can be easily resized.

Preloader Layout

Layout is pretty simple:

  1. <div class="preloader"></div>

This layout will work if you put preloader on a page before its initialization. If you need to add it page later or to use in custom layouts then use full preloader layout. It is different for each theme:

iOS Theme Preloader Layout

  1. <div class="preloader">
  2. <span class="preloader-inner">
  3. <span class="preloader-inner-line"></span>
  4. <span class="preloader-inner-line"></span>
  5. <span class="preloader-inner-line"></span>
  6. <span class="preloader-inner-line"></span>
  7. <span class="preloader-inner-line"></span>
  8. <span class="preloader-inner-line"></span>
  9. <span class="preloader-inner-line"></span>
  10. <span class="preloader-inner-line"></span>
  11. <span class="preloader-inner-line"></span>
  12. <span class="preloader-inner-line"></span>
  13. <span class="preloader-inner-line"></span>
  14. <span class="preloader-inner-line"></span>
  15. </span>
  16. </div>

MD Theme Preloader Layout

  1. <div class="preloader">
  2. <span class="preloader-inner">
  3. <span class="preloader-inner-gap"></span>
  4. <span class="preloader-inner-left">
  5. <span class="preloader-inner-half-circle"></span>
  6. </span>
  7. <span class="preloader-inner-right">
  8. <span class="preloader-inner-half-circle"></span>
  9. </span>
  10. </span>
  11. </div>

Aurora Theme Preloader Layout

  1. <div class="preloader">
  2. <span class="preloader-inner">
  3. <span class="preloader-inner-circle"></span>
  4. </span>
  5. </div>

Preloader Colors

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

MD theme also supports special color-multi color to make preloader multi-color.

  1. <!-- Red preloader -->
  2. <div class="preloader color-red"></div>
  3. <!-- Green preloader -->
  4. <div class="preloader color-green"></div>
  5. <!-- Multicolor preloader (MD theme only) -->
  6. <div class="preloader color-multi"></div>

Preloader Overlay / Preloader API

It is also possible to call special Preloader overlay which is useful if you need to block user actions until something is loaded. This kind of preloader will appear in front of app and block any user actions behind it.

Let’s look at related app methods to work with Preloader overlay

app.preloader.show(color)- show Preloader overlay

app.preloader.hide()- hide Preloader overlay

app.preloader.showIn(el, color)- show Preloader overlay in specified element

  • el - HTMLElement or string (with CSS Selector). Element where preloader overlay will be added
  • color - string. Preloader color, one of the default colors

app.preloader.hideIn(el)- hide Preloader overlay in specified element

  • el - HTMLElement or string (with CSS Selector). Element where preloader overlay should be removed from

For example:

  1. var app = new Framework7();
  2. // Show preloader before Ajax request
  3. app.preloader.show();
  4. // Perform Ajax request
  5. app.request.get('someurl.html', function (data) {
  6. // Hide preloader when Ajax request completed
  7. app.preloader.hide();
  8. });

Opening Preloader overlay will also add with-modal-preloader class to element.

CSS Variables

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

  1. :root {
  2. --f7-preloader-modal-padding: 8px;
  3. --f7-preloader-modal-bg-color: rgba(0, 0, 0, 0.8);
  4. }
  5. .ios {
  6. --f7-preloader-color: #6c6c6c;
  7. --f7-preloader-size: 20px;
  8. --f7-preloader-modal-preloader-size: 34px;
  9. --f7-preloader-modal-border-radius: 5px;
  10. }
  11. .md {
  12. --f7-preloader-color: #757575;
  13. --f7-preloader-size: 32px;
  14. --f7-preloader-modal-preloader-size: 32px;
  15. --f7-preloader-modal-border-radius: 4px;
  16. }
  17. .aurora {
  18. --f7-preloader-color: #757575;
  19. --f7-preloader-size: 24px;
  20. --f7-preloader-modal-preloader-size: 24px;
  21. --f7-preloader-modal-border-radius: 4px;
  22. }

Examples

  1. <div class="block-title">Default</div>
  2. <div class="block block-strong align-items-stretch text-align-center">
  3. <div class="row text-align-center">
  4. <div class="col-25">
  5. <div class="preloader"></div>
  6. </div>
  7. <div class="col-25" style="background: #222">
  8. <div class="preloader color-white"></div>
  9. </div>
  10. <!-- Large preloaders -->
  11. <div class="col-25">
  12. <div class="preloader" style="width: 44px; height: 44px"></div>
  13. </div>
  14. <div class="col-25" style="background: #222">
  15. <div class="preloader color-white" style="width: 44px; height: 44px"></div>
  16. </div>
  17. </div>
  18. </div>
  1. <div class="block-title">Color Preloaders</div>
  2. <div class="block block-strong">
  3. <div class="row">
  4. <div class="col-25">
  5. <div class="preloader color-red"></div>
  6. </div>
  7. <div class="col-25">
  8. <div class="preloader color-green"></div>
  9. </div>
  10. <div class="col-25">
  11. <div class="preloader color-orange"></div>
  12. </div>
  13. <div class="col-25">
  14. <div class="preloader color-blue"></div>
  15. </div>
  16. </div>
  17. </div>
  1. <div class="block-title">Multi-color (MD-theme only)</div>
  2. <div class="block block-strong text-align-center">
  3. <div class="preloader color-multi"></div>
  4. </div>
  1. <div class="block-title">Preloader Modals</div>
  2. <div class="block block-strong">
  3. <p>With <b>app.preloader.show()</b> you can show small overlay with preloader indicator.</p>
  4. <p>
  5. <a class="button button-raised open-preloader-indicator">Open Small Indicator</a>
  6. </p>
  7. </div>
  1. var app = new Framework7();
  2. var $$ = Dom7;
  3. $$('.open-preloader-indicator').on('click', function () {
  4. app.preloader.show();
  5. setTimeout(function () {
  6. app.preloader.hide();
  7. }, 3000);
  8. });

← Popup

Progressbar →