javascript - How to replace an image tag with an video tag in jsp -


how replace image tag video tag in jsp? trying display video after series of images on same position image time interval 1 sec.

the jsp code below:

<%--      document   : index     created on : apr 22, 2015, 8:33:41 pm     author     : name <vj> --%> <%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html> <html>     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8">         <title>cat clicker</title>         <script lang="javascript" src="changeimage.js"></script>     </head>     <body onload="changeimage();">         <img id="img1" style="position: absolute;top :35; left:170px; width:500px; height:250px" src="image/image.jpg" alt=""/>          <video id="vid1" style="position: absolute;top :35; left:170px; width:500px; height:250px" width="819" height="460">             <source src="" type="video/mp4">             browser not support video tag.                  </video>     </body> </html> 

the javascript function below:

/*   * change license header, choose license headers in project properties.  * change template file, choose tools | templates  * , open template in editor.  */  function changeimage() {    settimeout(function(){ document.getelementbyid("img1").src="image/cat 1.jpg";},1000);    settimeout(function (){ document.getelementbyid("img1").src="image/cat 2.jpg";},2000);    settimeout(function (){ document.getelementbyid("img1").src="";},3000);    settimeout(function () {document.getelementbyid("vid1").src = "image/vid1.mp4";    document.getelementbyid("vid1").play();}, 3000); } 

you eighter hide image-tag when showing video:

function changeimage() {    settimeout(function(){ document.getelementbyid("img1").src="image/cat 1.jpg";},1000);    settimeout(function (){ document.getelementbyid("img1").src="image/cat 2.jpg";},2000);    settimeout(function (){ document.getelementbyid("img1").src="";},3000);    settimeout(function () {document.getelementbyid("vid1").src = "image/vid1.mp4";    document.getelementbyid("img1").style.display = 'none';    document.getelementbyid("vid1").style.display = 'block';    document.getelementbyid("vid1").play();}, 3000); } 

or 'replace' image-tag follows:

wrap image in div unique id 'wrapper', put vid-tag inside of in function:

function changeimage() {    settimeout(function(){ document.getelementbyid("img1").src="image/cat 1.jpg";},1000);    settimeout(function () {document.getelementbyid("vid1").src = "image/vid1.mp4";    document.getelementbyid("wrapper").innerhtml = "<video id=\"vid1\" ....</video>";    document.getelementbyid("vid1").play();}, 3000); } 

in real life of course split several functions/objects. having html in function not nice way do.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -