Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use PNG, IMG file as background image? and can I add some css to animate effect on page? #2886

Closed
AppleBoiy opened this issue May 13, 2024 · 2 comments

Comments

@AppleBoiy
Copy link

Is there any way to use png as background? and is it possible to add some effect at background by using css

This is my current page

Screenshot 2567-05-13 at 17 16 36

This is my expectation

Screenshot 2567-05-13 at 17 16 36 png-1

from my expected image I have a background image (.PNG) and I want to add smoke effect by using css. is it possible?

@arno-fukuda
Copy link

You could wrap your mdx page in a Background component.

  1. add png or svg to /public/

  2. Create component

// Background.js
import React, { useState, useEffect } from "react"
import { useTheme } from "nextra-theme-docs"

const Background = ({ children }) => {
  const { resolvedTheme } = useTheme()
  const [backgroundImage, setBackgroundImage] = useState("")

  useEffect(() => {
    setBackgroundImage(
      resolvedTheme === "dark"
        ? "background/background_dark.svg"
        : "background/background_light.svg",
    )
  }, [resolvedTheme])

  return (
    <>
      <div
        style={{
          position: "fixed",
          top: 0,
          left: 0,
          width: "100%",
          height: "100%",
          zIndex: -1,
          backgroundImage: `url('${backgroundImage}')`,
          backgroundSize: "cover",
          backgroundRepeat: "no-repeat",
          backgroundPosition: "center",
          filter: "blur(6px)",
        }}
      />
      {children}
    </>
  )
}

export default Background
  1. Wrap your mdx page in it:
// index.mdx
import Background from 'components/Background'

<Background>

# Documents
...

</Background>

For animation, you can use an APNG or an svg from here as an example.

@AppleBoiy
Copy link
Author

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants