Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

77 linhas
1.9 KiB

  1. import React from "react";
  2. // nodejs library that concatenates classes
  3. import classNames from "classnames";
  4. // nodejs library to set properties for components
  5. import PropTypes from "prop-types";
  6. // @material-ui/core components
  7. import { makeStyles } from "@material-ui/core/styles";
  8. // core components
  9. import styles from "assets/jss/nextjs-material-kit/components/parallaxStyle.js";
  10. const useStyles = makeStyles(styles);
  11. export default function Parallax(props) {
  12. let windowScrollTop;
  13. // if (window.innerWidth >= 768) {
  14. // windowScrollTop = window.pageYOffset / 3;
  15. // } else {
  16. // windowScrollTop = 0;
  17. // }
  18. const [transform, setTransform] = React.useState("translate3d(0,0px,0)");
  19. React.useEffect(() => {
  20. if (window.innerWidth >= 768) {
  21. window.addEventListener("scroll", resetTransform);
  22. }
  23. return function cleanup() {
  24. if (window.innerWidth >= 768) {
  25. window.removeEventListener("scroll", resetTransform);
  26. }
  27. };
  28. });
  29. const resetTransform = () => {
  30. var windowScrollTop = window.pageYOffset / 3;
  31. setTransform("translate3d(0," + windowScrollTop + "px,0)");
  32. };
  33. const {
  34. filter,
  35. className,
  36. children,
  37. style,
  38. image,
  39. small,
  40. responsive
  41. } = props;
  42. const classes = useStyles();
  43. const parallaxClasses = classNames({
  44. [classes.parallax]: true,
  45. [classes.filter]: filter,
  46. [classes.small]: small,
  47. [classes.parallaxResponsive]: responsive,
  48. [className]: className !== undefined
  49. });
  50. return (
  51. <div
  52. className={parallaxClasses}
  53. style={{
  54. ...style,
  55. backgroundImage: "url(" + image + ")",
  56. transform: transform
  57. }}
  58. >
  59. {children}
  60. </div>
  61. );
  62. }
  63. Parallax.propTypes = {
  64. className: PropTypes.string,
  65. filter: PropTypes.bool,
  66. children: PropTypes.node,
  67. style: PropTypes.string,
  68. image: PropTypes.string,
  69. small: PropTypes.bool,
  70. // this will add a min-height of 660px on small screens
  71. responsive: PropTypes.bool
  72. };