Hello, my friends!
In this post, I want to show how easy it is to create a scroll indicator in Metro 4 using the progress component.
CSS
.indicator {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 1;
}
HTML
<div class="indicator" data-role="progress"></div>
JavaScript
function indicator(){
var container = document.documentElement;
var scrolled = (container.scrollTop / (container.scrollHeight - container.clientHeight)) * 100;
var pb = Metro.getPlugin(".indicator", 'progress');
pb.val(scrolled);
}
$(window).on('scroll', function(){
indicator()
})
indicator();
Comments
Hello,
i have error with your js.
it says : TypeError: pb is undefined
regards
Show your code, what Metro 4 version you use?
Example on codepen.io https://codepen.io/olton/pen/zYvwXOG
Hello, nevermind he worked on the sandbox, but he has still the error
https://sandbox.org.ua/floppy/debug/5m3jBTLYZx
regards
The first call to the indicator function occurred before the DOM was created. See the right example below:
https://sandbox.org.ua/olton/code/dNZJ81SJwv