Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a5afa46

Browse files
add ParallaxBanner component
1 parent eb1ce92 commit a5afa46

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

‎src/components/ParallaxBanner.js‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
3+
import Parallax from './Parallax';
4+
import { offsetMin, offsetMax } from '../utils/propValidation';
5+
6+
const constainerStyle = {
7+
position: 'relative',
8+
overflow: 'hidden',
9+
width: '100%',
10+
height: '50vh',
11+
};
12+
13+
const absolute = {
14+
position: 'absolute',
15+
top: 0,
16+
right: 0,
17+
bottom: 0,
18+
left: 0,
19+
};
20+
21+
const ParallaxBanner = ({ children, className, layers, style, disabled }) => {
22+
return (
23+
<div
24+
style={{ ...constainerStyle, ...style }}
25+
className={'parallax-banner' + (className ? ` ${className}` : '')}
26+
>
27+
{layers.map((layer, i) => (
28+
<Parallax
29+
key={`layer-${i}`}
30+
offsetYMax={layer.amount * 100 + '%'}
31+
offsetYMin={layer.amount * -1 * 100 + '%'}
32+
slowerScrollRate={layer.slowerScrollRate}
33+
styleInner={absolute}
34+
styleOuter={absolute}
35+
disabled={disabled}
36+
>
37+
<div
38+
className={`parallax-banner-layer-${i}`}
39+
style={{
40+
backgroundImage: `url(${layer.image})`,
41+
backgroundPosition: 'center',
42+
backgroundSize: 'cover',
43+
...absolute,
44+
top: layer.amount * 100 * -1 + '%',
45+
bottom: layer.amount * 100 * -1 + '%',
46+
}}
47+
/>
48+
</Parallax>
49+
))}
50+
{children}
51+
</div>
52+
);
53+
};
54+
55+
ParallaxBanner.defaultProps = {
56+
disabled: false,
57+
};
58+
59+
ParallaxBanner.propTypes = {
60+
className: PropTypes.string,
61+
children: PropTypes.node,
62+
disabled: PropTypes.bool.isRequired,
63+
layers: PropTypes.arrayOf(
64+
PropTypes.shape({
65+
amount: PropTypes.number.isRequired,
66+
image: PropTypes.string.isRequired,
67+
slowerScrollRate: PropTypes.bool,
68+
})
69+
),
70+
style: PropTypes.object,
71+
};
72+
73+
export default ParallaxBanner;

‎src/index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export Parallax from './components/Parallax';
22
export ParallaxProvider from './components/ParallaxProvider';
3+
export ParallaxBanner from './components/ParallaxBanner';
34
export ParallaxController from './libs/ParallaxController';

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /