Building a floating video player using React

I recently installed the React-Player module and it is functioning perfectly. However, I am encountering some difficulties in trying to embed the player within an Element so that it appears as a floating player across my application, regardless of the page I navigate to.

return (
        <PageContainer maxWidth="xl">
            <Table
                config={{...groupsTable, label: page}}
                onActions={getAction}
                processData={groupsCb}
                reload={reload}
                setReload={setReload}
                props={{
                    params: {
                        _id: urlParams.id,
                    },
                }}
            />
            {showPlayer ? 
            <div className="player-wrapper">
                <Button onClick={closePlayer}>Close</Button>
                <ReactPlayer url={currentVideo} muted={true} controls={true} pip={true} playing={false} />
            </div> : null}

            <Create onClick={createNewGroup}/>`your text`
        </PageContainer>
    )

`

As you can see, I have enclosed the player in a div with a className of "player-wrapper", but my CSS styling is not producing the desired results....

Is there a more effective approach to ensure that the video starts in the right-hand corner, remains contained within its own element, and stays visible throughout the application as I navigate?

CSS:

.player-wrapper {
    position: fixed;
    width: 450px;
    height: 300px;
    bottom: 40px;
    right: 40px;
    background: #000;
}

Answer №1

If you want to add drag-and-drop functionality to an element in your HTML, simply use the attribute draggable="true". By determining the offset of your element from the top or bottom, you can accurately position it using position: absolute and adjusting the top property accordingly. This method allows you to create a draggable element on your webpage. To learn more about this feature, feel free to visit the following link and experiment with it yourself.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Arranging images in a row with the help of :before and :after styling

Looking to use the pseudo selectors :before and :after to create a border around a div with images, but running into some issues. The :after image is not positioning correctly on the right side of the element and the text is dropping below the image. Check ...

Achieving asynchronous results in the parent function with TypeScript: a guide

The code structure provided is as follows: import {socket} from './socket'; class A{ Execute(...args[]){ //logic with Promises SomeAsyncMethod1().then(fulfilled1); function fulfilled1(){ SomeAsyncMethod2(args).then(fulfilled2); ...

Stylized with different images scattered across the browser window

Is there a way to ensure that all my randomly positioned images stay within the bounds of their 100% wrap without being cut off? Currently, some images are getting cut off due to the overflow: hidden setting. Also, is it possible to prevent the images from ...

The primary origin of TypeScript is derived from the compiled JavaScript and its corresponding source map

Being new to sourcemaps and typescript, I am faced with a project that has been compiled into a single javascript file from multiple typescript files. The files available to me are: lib.js (the compiled js code of the project) lib.js.map (the source map ...

Steps to enable checkbox functionality in Chakra UI

I need help implementing a checkbox functionality in my project. I am using Chakra UI and trying to achieve a scenario where clicking on the parent checkbox checks all the children checkboxes, but also allows for individual selection. The challenge I am ...

Exploring Angular 8 HTTP Observables within the ngOnInit Lifecycle Hook

Currently, I am still a beginner in Angular and learning Angular 8. I am in the process of creating a simple API communication service to retrieve the necessary data for display. Within my main component, there is a sub-component that also needs to fetch ...

Utilize JavaScript to iterate through a JSON object and retrieve the indices that meet the specified criteria

While I found a previous answer that somewhat addresses my issue, I am seeking guidance on how to return an array of the indexes where a specific value appears. For example, if **18A38** is the target value, it should return the positions [1,3]. The sampl ...

What is causing the align content property to not function as expected in this situation?

Is it expected for the flex items of the .center-section-container to be closer together when using this property? They do not seem to be affected at all. I have applied flex wrap so the items are now in different lines but too far away from each other, I ...

Error: Module 'electron-prebuilt' not found

I am encountering an issue with my Electron app that utilizes Nightmare.js after compiling it into an .exe file using electron-packager. Everything functions properly until I click a button that triggers Nightmare.js, at which point I receive the followi ...

New post: "Exploring the latest features in Angular

Looking for help with integrating Angular and SpringREST to fetch data from the backend? Here's my situation: I need to retrieve a JSON string from the backend using a POST request, send it to my site's hosted link, and display it on the user int ...

Is there a way to eliminate the mongoose event listener registered onConnect in the Socket.io Leak issue?

Whenever a user connects via socket.io, the following subscribe event is triggered: socket.on('subscribe', function(room) { console.log('joining room', room.id); socket.join(room.id); socket.roomName = room.id; // ...

Changing an array into a list using javascript

function convertArrayToList(inputArray) { let list = null; for (let i = inputArray.length - 1; i >= 0; i--) { list = { value: inputArray[i], rest: list }; } return list; } let result = convertArrayToList([10, 20]); console.log(JSON.stringi ...

Allowing the primary content to span the entire width of the mobile screen

I have scoured various forums in search of answers, but unfortunately, I haven't found a solution that fits my specific query. I am looking to ensure that the .main-content (article text and images) occupies the full width of the mobile screen without ...

What is the best way to hear an event emitted by a component?

I am trying to listen for an event in Chrome DevTools Vue, but I'm not sure how to target it. For a Root event, I typically use: this.$root.$on("note_id", (note_id) => (this.note_id = note_id)); But how do I address an event that origina ...

The received reply does not align with the set parameter configuration:

Encountering an issue with Angular $resource: error description Error: error:badcfg Response does not match configured parameter: Error in resource configuration for action `array`. Expected response to contain an object but got an {2} Initialization of ...

What is the best way to send root parameters within the resolver function of a nested query?

I have a question regarding the structure of my GraphQL queries Category1(name: $cat1){ Category2(secondName: $cat2){ secondName }} This is how my schema is set up: const Query = new GraphQLObjectType({ name: 'Query', fields: { ...

Having trouble getting CSS Animation to work in a React project?

I am currently developing a Next.js application using React. const partyButton = useRef(null) const handleParty = () => { setTimeout(() => { partyButton.current.classList.add('party-time'); console.log(party ...

Utilizing the click event with a Bootstrap modal: A guide

I have a PHP script that generates multiple Bootstrap modals, and I want to be able to modify some input fields when the "save changes" button is clicked. The ModalIDs generated are in the format "ModalID0000". However, nothing happens when I click on the ...

Automatically resetting the Redux toolkit store when navigating between pages in Next.js

I am a new Next user who has been using Redux with React for a while. However, I encountered many challenges when trying to integrate Redux with Next. I have decided to move on from this solution. store.js import { configureStore } from '@reduxjs/to ...

The vertical-align property in CSS seems to be malfunctioning

Hi there, I'm struggling with the CSS code below: .parent { position : 'absolute'; top : '50px'; left : '50px'; width : '400px'; height : '160px'; padding : '10px'; ...