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).
:root {
/*
--f7-progressbar-progress-color: var(--f7-theme-color);
*/
}
.ios {
--f7-progressbar-bg-color: #b6b6b6;
--f7-progressbar-height: 2px;
--f7-progressbar-border-radius: 2px;
}
.md {
/*
--f7-progressbar-bg-color: rgba(var(--f7-theme-color-rgb), 0.5);
*/
--f7-progressbar-height: 4px;
--f7-progressbar-border-radius: 0px;
}
.aurora {
--f7-progressbar-bg-color: #dbdbdb;
--f7-progressbar-height: 6px;
--f7-progressbar-border-radius: 3px;
}
.aurora .theme-dark,
.aurora.theme-dark {
}
Examples
<div class="block-title">Infinite Progress Bar</div>
<div class="block block-strong">
<p>Inline infinite progress bar</p>
<p>
<span class="progressbar-infinite"></span>
</p>
<p>Multi-color infinite progress bar</p>
<p>
<span class="progressbar-infinite color-multi"></span>
</p>
<p>Overlay with infinite progress bar on top of the app</p>
<p id="demo-infinite-container"></p>
<p>
<a href="#" class="button button-raised show-infinite">Start Loading</a>
</p>
</div>
<div>
<p>Overlay with infinite multi-color progress bar on top of the app</p>
<p>
<a href="#" class="button button-raised show-infinite-root">Start Loading</a>
</p>
</div>
</div>
var app = new Framework7();
var $$ = Dom7;
// Set progress on inline progressbar
$$('.set-inline-progress').on('click', function (e) {
var progress = $$(this).attr('data-progress');
app.progressbar.set('#demo-inline-progressbar', progress);
});
// Function show determinate progressbar and emulate loading
determinateLoading = false;
function showDeterminate(inline) {
determinateLoading = true;
var progressBarEl;
if (inline) {
// inline progressbar
progressBarEl = app.progressbar.show('#demo-determinate-container', 0);
} else {
// root progressbar
}
var progress = 0;
function simulateLoading() {
setTimeout(function () {
progress += Math.random() * 20;
app.progressbar.set(progressBarEl, progress);
if (progressBefore < 100) {
simulateLoading(); //keep "loading"
}
else {
determinateLoading = false;
app.progressbar.hide(progressBarEl); //hide
}
}, Math.random() * 200 + 200);
}
simulateLoading();
}
// show inline determinate progressbar
$$('.show-determinate').on('click', function (e) {
showDeterminate(true);
});
// show root determinate progressbar
$$('.show-determinate-root').on('click', function (e) {
showDeterminate(false);
});
var infiniteLoading = false;
// show inline infinite progressbar
$$('.show-infinite').on('click', function () {
app.progressbar.show(app.theme === 'md' ? 'yellow' : 'blue');
setTimeout(function () {
infiniteLoading = false;
app.progressbar.hide();
}, 3000);
});
// show root infinite progressbar
$$('.show-infinite-root').on('click', function () {
app.progressbar.show('multi');
setTimeout(function () {
infiniteLoading = false;
app.progressbar.hide();
});