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

richi-coder/parallax-effect

Repository files navigation

PARALLAX EFFECT WITH PURE CSS (NO JS)

NO NEED TO USE JAVASCRIPT!

Requires patience!

πŸ§‘β€πŸš€ Check the code!

πŸš€ How to do it:

0.- Focus only on this exercise before adding it to your project. This requires not using the BODY element.

1.- Create a div class "wrapper" element inside the body element and set the following CSS to it:

.wrapper {
 margin: 0;
 padding: 0;
 width: 100vw;
 height: 100vh;
 overflow-y: auto;
 overflow-x: hidden;
 display: flex;
 flex-direction: column;
 perspective: 10px;
 position: fixed;
 top: 0;
 left: 0;
 }
  • As you can see, this wrapper element will contain the rest of HTML elements and will be scrolling, instead of scrolling body, main or html.

2.- Create another div inside the "wrapper", call it "sub". Add this CSS to it:

.sub {
 display: flex;
 flex-direction: column;
 position: relative;
 height: 100vh;
 transform-style: preserve-3d;
 z-index: -1;
}
  • This div will containt the element that will produce the parallax effect.

3.- Create two elements to try the effect as next:

/ β”œβ”€β”€ public/ β”‚ └── favicon.svg β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ components/ β”‚ β”‚ └── Card.astro β”‚ β”œβ”€β”€ layouts/ β”‚ β”‚ └── Layout.astro β”‚ └── pages/ β”‚ └── index.astro └── package.json


Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.
There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.
Any static assets, like images, can be placed in the `public/` directory.
## 🧞 Commands
All commands are run from the root of the project, from a terminal:
| Command | Action |
| :--------------------- | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:3000` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro --help` | Get help using the Astro CLI |
## πŸ‘€ Want to learn more?
Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).

About

Parallax Effect Pure CSS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /