css - Angular 12: Add class base on element current position and window position
问题描述
I'm trying to add some scrolling animation to my app which is something like this: when the user start scrolling, elements will start sliding in or out depending on whether they are about to be in-view or soon to be out-of-view.
My idea is to keep track of the window position like this:
curWinPos: number = 0;
@HostListener('window:scroll', ['$event'])
windowScrolled($event: Event) {
this.curWinPos = window.scrollY;
}
and then add the "show" class to the element base on their current position compare to curWinPos:
<div [class.show]="$element.getBoundingClientRect().top === curWinPos"
I have no idea how to access the "$element" in the template though
解决方案
推荐阅读
- java - Android 10 和 11 java.lang.SecurityException:不允许使用前台服务删除通道 MyNotificationChannel
- php - 在页面 edit-post.php 上创建新标签
- python-3.x - 在子图中使用嵌套的 for 循环
- angular - 即使我必须在我的 Angular 应用程序中调用 super(),我如何将东西注入父类构造函数?
- c# - 无法替换 WixVariable 值
- python - pandas 数据透视表:带边距的自定义 aggfunc
- android - 片段未附加到上下文
- http-status-code-302 - 处理 Http 状态码 302 临时移动
- kotlin - Kotlin:类型不匹配:推断类型是字符串?但字符串是预期的
- javascript - 如何在javascript中展平具有3个条目的二维数组?