Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to move a <video> element in the DOM without resetting it?

Tags:

html

dom

I'd like to create a <video> element within my DOM, and then move it to another position without interrupting the playing of that content.

Perhaps more broadly, is it possible to move any DOM element without disrupting attached events?

Some approaches include using CSS absolute positioning, but is there a way to actually update the DOM in a way that doesn't interrupt the playback?

like image 586
Eric Martindale Avatar asked Dec 10 '13 18:12

Eric Martindale


People also ask

How do you move an element with DOM?

To move element in the DOM in JavaScript, we can use the before and after methods. const div1 = document. getElementById("div1"); const div2 = document.

How do you grab elements from DOM?

The easiest way to access a single element in the DOM is by its unique ID. You can get an element by ID with the getElementById() method of the document object. In the Console, get the element and assign it to the demoId variable. Logging demoId to the console will return our entire HTML element.

How do you move an element in JavaScript?

In plain JavaScript, you can use the appendChild() method to move the existing source element in the document to the target element.

How do you unload a video in HTML?

Just put your src to null. It will remove your video src attribute. Done.


1 Answers

Unfortunately not. The DOM doesn't really have a concept of move, you just have to detach and reattach. As soon as the DOM node is no longer rooted in a document, it loses its playing state.

You may be able to preserve it somewhat by storing it in JS and re-applying it, but that will probably introduce a little skipping.

like image 86
loganfsmyth Avatar answered Sep 24 '22 01:09

loganfsmyth