如何实现Vue滚动时固定顶部并自定义样式?
- 内容介绍
- 文章标签
- 相关推荐
本文共计389个文字,预计阅读时间需要2分钟。
滚动固定定位有多种方法:
1.使用CSS3的粘性定位:`position: sticky; top: 20px;`
2.直接使用`position: fixed;`定位顶部盒子,并设置`margin-top`。
3.通过事件监听器监控并更新`style`中的`position`属性。
修改样式滚动固定位置有多种方法
1 css3 粘性定位
position:sticky; top:20px;
2直接position:fixed;给顶部盒子设置一个margin-top刚好是需要固定的盒子的高度
3事件监听更改style中的position属性
**
修改样式
滚动监听事件中使用this.$refs.xxx.style.color=‘xxxx' 这种方式会报错
Uncaught TypeError: Cannot read property 'style' of undefined
所以通过动态绑定来解决。
本文共计389个文字,预计阅读时间需要2分钟。
滚动固定定位有多种方法:
1.使用CSS3的粘性定位:`position: sticky; top: 20px;`
2.直接使用`position: fixed;`定位顶部盒子,并设置`margin-top`。
3.通过事件监听器监控并更新`style`中的`position`属性。
修改样式滚动固定位置有多种方法
1 css3 粘性定位
position:sticky; top:20px;
2直接position:fixed;给顶部盒子设置一个margin-top刚好是需要固定的盒子的高度
3事件监听更改style中的position属性
**
修改样式
滚动监听事件中使用this.$refs.xxx.style.color=‘xxxx' 这种方式会报错
Uncaught TypeError: Cannot read property 'style' of undefined
所以通过动态绑定来解决。

