Skip to content

Instantly share code, notes, and snippets.

@aasumitro
Created March 22, 2022 10:16
Show Gist options
  • Save aasumitro/6ebefac5d18d46d0bf09ab1ecec342c2 to your computer and use it in GitHub Desktop.
Save aasumitro/6ebefac5d18d46d0bf09ab1ecec342c2 to your computer and use it in GitHub Desktop.
Scroll Indicator
<ion-content>
<section>
<div class="header"> </div>
<div class="items-horizontal"> item . . . . (for-loop) </div>
<div class="indicator-tray">
<div class="indicator"></div>
</div>
</section>
</ion-content>
ion-content {
section {
.indicator-tray {
width: 40px;
height: 4px;
background: #D7D7D7;
border-radius: 4px;
margin: 0 auto;
.indicator {
width: 0;
height: inherit;
background: #0BDBD2;
border-radius: 4px;
}
}
}
}
import { ElementRef, OnInit,} from '@angular/core';
@Component({
selector: 'app-page',
templateUrl: './page.html',
styleUrls: ['./page.scss'],
})
export class Page implements OnInit {
constructor(
public element: ElementRef,
) { }
ngOnInit() {
// ! listener for indicator start
const indicator =
this.element
.nativeElement
.querySelector('.indicator')
const itemContainer =
this.element
.nativeElement
.querySelector('.items-horizontal');
itemContainer.addEventListener('scroll', function (event) {
const scroll = itemContainer.scrollLeft;
const width = itemContainer.scrollWidth - itemContainer.clientWidth;
const scrolled = (scroll / width) * 100;
indicator.style.width = `${scrolled}%`;
});
// ! listener for indicator end
}
}
@aasumitro
Copy link
Author

indicator.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment