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:
<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
<div class="preloader">
<span class="preloader-inner">
<span class="preloader-inner-line"></span>
<span class="preloader-inner-line"></span>
<span class="preloader-inner-line"></span>
<span class="preloader-inner-line"></span>
<span class="preloader-inner-line"></span>
<span class="preloader-inner-line"></span>
<span class="preloader-inner-line"></span>
<span class="preloader-inner-line"></span>
<span class="preloader-inner-line"></span>
<span class="preloader-inner-line"></span>
<span class="preloader-inner-line"></span>
<span class="preloader-inner-line"></span>
</span>
</div>
MD Theme Preloader Layout
<div class="preloader">
<span class="preloader-inner">
<span class="preloader-inner-gap"></span>
<span class="preloader-inner-left">
<span class="preloader-inner-half-circle"></span>
</span>
<span class="preloader-inner-right">
<span class="preloader-inner-half-circle"></span>
</span>
</span>
</div>
Aurora Theme Preloader Layout
<div class="preloader">
<span class="preloader-inner">
<span class="preloader-inner-circle"></span>
</span>
</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.
<!-- Red preloader -->
<div class="preloader color-red"></div>
<!-- Green preloader -->
<div class="preloader color-green"></div>
<!-- Multicolor preloader (MD theme only) -->
<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
- parameters - color. Preloader color, one of the default colors
app.preloader.hide()- hide Preloader overlay
For example:
var app = new Framework7();
// Show preloader before Ajax request
app.preloader.show();
// Perform Ajax request
app.request.get('someurl.html', function (data) {
// Hide preloader when Ajax request completed
app.preloader.hide();
});
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).
:root {
--f7-preloader-modal-padding: 8px;
--f7-preloader-modal-bg-color: rgba(0, 0, 0, 0.8);
}
.ios {
--f7-preloader-color: #6c6c6c;
--f7-preloader-size: 20px;
--f7-preloader-modal-preloader-size: 34px;
--f7-preloader-modal-border-radius: 5px;
}
.md {
--f7-preloader-color: #757575;
--f7-preloader-size: 32px;
--f7-preloader-modal-preloader-size: 32px;
--f7-preloader-modal-border-radius: 4px;
}
.aurora {
--f7-preloader-color: #757575;
--f7-preloader-size: 24px;
--f7-preloader-modal-preloader-size: 24px;
--f7-preloader-modal-border-radius: 4px;
}
Examples
<div class="block-title">Default</div>
<div class="block block-strong align-items-stretch text-align-center">
<div class="row text-align-center">
<div class="col-25">
<div class="preloader"></div>
</div>
<div class="col-25" style="background: #222">
<div class="preloader color-white"></div>
</div>
<!-- Large preloaders -->
<div class="col-25">
<div class="preloader" style="width: 44px; height: 44px"></div>
</div>
<div class="col-25" style="background: #222">
<div class="preloader color-white" style="width: 44px; height: 44px"></div>
</div>
</div>
</div>
<div class="block-title">Color Preloaders</div>
<div class="block block-strong">
<div class="row">
<div class="col-25">
<div class="preloader color-red"></div>
</div>
<div class="col-25">
<div class="preloader color-green"></div>
</div>
<div class="col-25">
<div class="preloader color-orange"></div>
</div>
<div class="col-25">
<div class="preloader color-blue"></div>
</div>
</div>
</div>
<div class="block-title">Multi-color (MD-theme only)</div>
<div class="block block-strong text-align-center">
<div class="preloader color-multi"></div>
</div>
<div class="block-title">Preloader Modals</div>
<div class="block block-strong">
<p>With <b>app.preloader.show()</b> you can show small overlay with preloader indicator.</p>
<p>
<a class="button button-raised open-preloader-indicator">Open Small Indicator</a>
</p>
</div>
var app = new Framework7();
var $$ = Dom7;
$$('.open-preloader-indicator').on('click', function () {
app.preloader.show();
setTimeout(function () {
app.preloader.hide();
}, 3000);
});