angular - 在角度动画中的过渡期间隐藏滚动条
问题描述
我需要在过渡期间隐藏滚动条的帮助。
trigger("routeFadeState", [
transition(":enter", [
style({
transform: "translateY(-100vh)"
}),
animate("1000ms ease-out")
]),
transition(":leave",
animate(
"500ms",
style({
transform: "translateY(-100vh)",
overflow: hidden
})
)
)
]);
我正在尝试在 :enter 上实现 slideInfromTop 和在 :leave 上实现 slideOutToTop 。slideIn 的屏幕应该占据全屏高度和全屏宽度。
在 :enter 期间,我的代码运行良好。屏幕平滑滑动,既没有垂直滚动条也没有水平滚动条。滚动条根本不出现。
在 :leave 期间,虽然屏幕滑出,但我看到滚动条出现了一瞬间。我想摆脱那个。
我不使用任何 CSS 框架。
请帮帮我
解决方案
There are many items which lead to the scrollbars.
- The html body defaults to some margin and padding lose them first in your global CSS
html, body {
margin: 0;
padding: 0;
}
- In your global styles I added the
position:absolute
part to all component that will be loaded in the <router-outlet> so all component will be positioned absolutely so you don't have to go to each component and writeposition: absolute
,display: block
,width
andheight
. Your styles for your global css for your routed component as follows
router-outlet + * {
position: absolute;
display: block;
height: 100vh;
width: 100vw;
}
- Update your component CSS (Optional). So now your components CSS become simple:
Home (CSS) | About (CSS)
:host { | :host {
background-color: yellow; | background-color: red;
} | }
- Last thing the notorious one: Lose the <p> tags or lose their margins (always bangs my head good) use <div> tags. They impact the overall page margin somehow.
Updated Stackblitz: https://stackblitz.com/edit/angular-qdxphn
Now you have a much cleaner base and route animations will never trouble you again.
Cheers✌</p>
推荐阅读
- javascript - 如果用户未登录反应如何隐藏导航
- java - 上传您自己的头像
- python - Python Dataframe:使用 astype 更改列类型失败
- json - 使用 ClickHouse 使用来自 Kafka 的嵌套 JSON 消息
- sql - T-SQL 在用作默认值的函数中使用列名作为参数
- java - 为什么我的累加器不增加并且总是返回零?
- visual-studio-code - 为什么“npm script”出现在我的资源管理器中?
- react-native - 什么可以使功能在模拟器上运行而不是在设备上运行?
- html - CSS:可视化隐藏y轴滚动条而不影响x轴滚动条
- html - 如何消除 React JS 中 Font Awesome Icon 和段落之间的差距?