I hope you could give me a few minutes of your time. I am trying to implement a dark background canvas to cover up a video in its background, the code beneath should be able to do that with fill style and the source over, but for some reason it is not, do you have an Idea of how to solve this?
let canvas = useRef(null);
const size = useWindowSize();
const { currentTheme } = useGlobalStateContext()
useEffect(() => {
let renderingElement = canvas.current;
let drawingElement = renderingElement.cloneNode();
let drawingCtx = drawingElement.getContext("2d");
let renderingCtx = drawingElement.getContext("2d");
let lastX;
let lastY;
let moving = false;
renderingCtx.globalCompositeOperation = "source-over"
renderingCtx.fillStyle = currentTheme === "dark" ? "#000000" : "#ffffff";
renderingCtx.fillRect(0,0, size.width, size.height)
console.log(renderingCtx)
}, [])
return (
<Banner>
<Video>
<video
height="100%"
width="100%"
loop
autoPlay
src={require("../../assets/video/video.mp4")}
/>
</Video>
<Canvas
height={size.height}
width={size.width}
ref={canvas}
/>
<BannerTitle variants={container} initial="initial" animate="animate">
<Headline variants={item}>DIG</Headline>
<Headline variants={item}>DEEP</Headline>
</BannerTitle>
</Banner>
)
}
=============================== i am making use of styled components,
import styled from "styled-components"
import { motion } from "framer-motion"
//Banner
export const Banner = styled.div`
background: ${props => props.theme.background};
height: 100vh;
width: 100%;
position: relative;
margin-bottom: 296px;
`
export const Video = styled.div`
height: 100%;
width: 100%;
video {
object-fit: cover;
}
`
export const Canvas = styled.canvas`
position: absolute;
top: 0;
left: 0;
height: 100%;
display: block;
`
This block of code is applying a dark background to the canvas so it can cover up the video behind it but instead of covering the video up (the screen would be dark and the video will be playing in the background) instead something else shows
This is the image of the final result