b4l*_*4g3 5 css scroll reactjs scroll-snap-points styled-components
我在不同的最新浏览器上对其进行了测试,因此它不可能是兼容性问题。我正在使用带有样式组件的 create-react-app,这是我的代码:
import React, { Component } from 'react';
import styled, { createGlobalStyle } from 'styled-components';
const GlobalStyle = createGlobalStyle`
@import url('https://fonts.googleapis.com/css?family=Merriweather|Oleo+Script');
`
const Wrapper = styled.div`
scroll-snap-type: y mandatory;
display: flex;
flex-direction: column;
font-size: 16px;
`
const Home = styled.div`
scroll-snap-align: center;
height: 100vh;
background-color: yellow;
display: flex;
flex-direction: row;
`
const Menu = styled.div`
scroll-snap-align: center;
height: 100vh;
background-color: blue;
display: grid;
`
const Speciality = styled.div`
scroll-snap-align: center;
height: 100vh;
background-color: green;
`
class App extends Component {
render() {
return (
<Wrapper>
<GlobalStyle />
<Home />
<Menu />
<Speciality />
</Wrapper>
);
}
}
export default App;
Run Code Online (Sandbox Code Playgroud)
当我滚动时它没有做任何事情,我几乎尝试过任何事情。如果没有样式组件,它也不会工作。
编辑:我将我的代码复制到了codesandbox:https ://codesandbox.io/s/72jmn1p1w1
小智 5
在您的代码沙箱中,我已将 Wrapper 元素代码替换为以下内容以使其正常工作:
const Wrapper = styled.div`
scroll-snap-type: y mandatory;
max-height: 100vh;
overflow-y: scroll;
`;
Run Code Online (Sandbox Code Playgroud)
这解决了一些问题:
| 归档时间: |
|
| 查看次数: |
1875 次 |
| 最近记录: |