Friday, 24 October 2014

Playing YouTube Video on HTML page

You can also embed HTML video code into your web page using the <object> tag. To cater for browsers that don't support the <object> tag, you can nest the <embed> tag inside the <object> tag.
Listed example will cover a demonstration of adding YouTube video.
Listing : Playing YouTube Video on Page
<!DOCTYPE html>
<html>
<head>
<title>HTML Video Tag Example</title>
</head>
<body>

<object width="425" height="350">
<param name="movie" value="http://www.youtube.com/v/tIBxavsiHzM" />
<embed src="http://www.youtube.com/v/tIBxavsiHzM" type="application/x-shockwave-flash" width="425" height="350" />
</object>
</body>
</html>





Figure 2: Above figure is example of demonstration of adding YouTube video on page.
The above script is supported by IE 7.

Adding video file on page

For this we have taken a particular height and width to show the video. attribute control adds video controls, like play, pause, and volume adjusting seek bar.
Listing 1: Script to Adding Simple Video File on Page
<!DOCTYPE html>
<html>
<head>
<title>HTML Video Tag Example</title>
</head>
<body>
<video width="320" height="240" controls="controls" autoplay="autoplay">
<source src="dhoom.mp4" type="video/mp4">
<object data="" width="320" height="240">
<embed width="320" height="240" src="dhoom.mp4">
</object>
</video>
</body>
</html>




Figure 1: This figure is output of embeding simple video on page in HTML.
Here we saw that the control attribute adds video controls, like play, pause, and volume adjusting seek bar. Also it can be seen that the video is being played in particular region on page, reason is we have included width and height attributes for playing the video. If height and width are set, the space required for the video is reserved when the page is loaded. However, without these attributes, browser will adjust itself or will display to full page.
There was no standard procedure to play video on web pages. Most videos today are shown through flash or various plug-in. However, different browsers may have different plug-ins. Without any standardized method it becomes difficult to provide different plug-ins for different browsers. As a remedy to this, HTML5 defines a new element which specifies a standard way to embed a video/movie on a web page: the <video> element. This <video> element is supported by all major browsers such as Internet explorer, Google Chrome, Safari, Opera etc.
The <video> element was proposed by Opera Software in February 2007 Opera also released a preview build that was showcased the same day, and a manifest that called for video to become a first-class citizen of the web.


Shake image using javascript

Move over JavaScript onMouseover scripts, your DHTML cousin is in town. The very first of its kind anywhere on the web (as least at time of writing), this script "shakes" an image when the mouse comes in contact with it. Use it to add instant eye-popping effect to your image links.

Step 1: Insert the below into the <head> section of your page:

<style>
.shakeimage{
position:relative
}
</style>
<script language="JavaScript1.2">


//configure shake degree (where larger # equals greater shake)
var rector=3

///////DONE EDITTING///////////
var stopit=0 
var a=1

function init(which){
stopit=0
shake=which
shake.style.left=0
shake.style.top=0
}

function rattleimage(){
if ((!document.all&&!document.getElementById)||stopit==1)
return
if (a==1){
shake.style.top=parseInt(shake.style.top)+rector+"px"
}
else if (a==2){
shake.style.left=parseInt(shake.style.left)+rector+"px"
}
else if (a==3){
shake.style.top=parseInt(shake.style.top)-rector+"px"
}
else{
shake.style.left=parseInt(shake.style.left)-rector+"px"
}
if (a<4)
a++
else
a=1
setTimeout("rattleimage()",50)
}

function stoprattle(which){
stopit=1
which.style.left=0
which.style.top=0
}


</script>


Step 2: Add the below inside the <img> tag of all of the images you want the effect applied to:

class="shakeimage" onMouseover="init(this);rattleimage()" onMouseout="stoprattle(this);top.focus()" onClick="top.focus()"


An example would be:

<img src="man.gif" class="shakeimage" onMouseover="init(this);rattleimage()" onMouseout="stoprattle(this);top.focus()" onClick="top.focus()">