Window resize
See original GitHub issueThis is great! Thank you so much for this.
I noticed that when the browser window is resized it causes the canvas to stretch/shrink which causes the confetti particles to look pretty ugly. I solved it in user-land using the code below. But I was wondering if this wouldn’t better be solved by the library itself?
I wouldn’t mind opening a PR, I just wanted to get your input first before I work on it.
constructor(props) {
super(props);
this.state = {
confetti: {
width: '100%',
height: '100%',
},
};
this.updateDimensions = this.updateDimensions.bind(this);
}
componentDidMount() {
window.addEventListener('resize', this.updateDimensions);
}
componentWillUnmount() {
window.removeEventListener('resize', this.updateDimensions);
}
updateDimensions() {
const main = document.querySelectorAll('#main')[0].getBoundingClientRect();
this.setState({
confetti: {
width: main.width,
height: main.height,
},
});
}
render() {
return (
<App
{...this.props}
title="Registration Complete"
innerRef={(c) => { this.app = c; }}
>
<Confetti
gravity={0.05}
numberOfPieces={100}
colors={[
'rgba(255, 255, 255, 0.1)',
]}
style={{ top: '-1px' }} // fix bug that shows black line
{...this.state.confetti} // allows for browser resizing without stretching
/>
<FlexHelper>
<p><strong>Registration Complete</strong></p>
<p>
...
</p>
</FlexHelper>
</App>
);
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Window: resize event - Web APIs | MDN
The resize event fires when the document view (window) has been resized. This event is not cancelable and does not bubble.
Read more >JavaScript window resize event - Stack Overflow
You should use ResizeObserver. It is a browser-native solution that has a much better performance than to use the resize event. In addition,...
Read more >.resize() | jQuery API Documentation
Description: Bind an event handler to the "resize" JavaScript event, ... The resize event is sent to the window element when the size...
Read more >onresize Event - W3Schools
The onresize event occurs when the browser window has been resized. Tip: To get the size of an element, use the clientWidth, clientHeight,...
Read more >How to resize a window - Computer Hope
Press Alt + Spacebar to open the window's menu. · If the window is maximized, arrow down to Restore and press Enter ....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@aesopwolf Glad you’re getting some use out of it and thanks for the suggestion!
In the interest of keeping the component simple, I think it might be best to keep all the dimension operations external.
I actually just solved this same problem in another project using react-dimensions. Very helpful little util.
Thanks @adrianmcli !
I just updated the demo to actually use the
react-dimensions
also.