【发布时间】:2019-07-14 01:22:01
【问题描述】:
我在不同的最新浏览器上对其进行了测试,因此它不会是兼容性问题。 我正在使用带有样式组件的 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;
当我滚动时它什么也没做,我几乎尝试过任何东西。 如果没有样式组件,它也将无法工作。
编辑:我将我的代码复制到代码框:https://codesandbox.io/s/72jmn1p1w1
【问题讨论】:
-
它在 chrome 中滚动正常 - 它到底有什么作用?
-
@Mikkel 它应该像这样滚动:i.imgur.com/vMW8ALh.gif
-
我也无法使用 React 中的样式组件使 css 滚动对齐。我已经集成了与snap.glitch.me/product.html 相同的代码,但无法正常工作。
标签: css reactjs scroll styled-components scroll-snap-points