Created
March 22, 2022 10:16
-
-
Save aasumitro/6ebefac5d18d46d0bf09ab1ecec342c2 to your computer and use it in GitHub Desktop.
Scroll Indicator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
indicator.mp4