how to create a moving div?

Answer Posted / mangala

Creating the moving DIV :
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en">

<head>


<style type="text/css">
</style>

<script type="text/javascript">
function moveDiv()
{
var the_style = getStyleObject("myDiv");
var the_left = parseInt(the_style.left) + 100;
var the_top = parseInt(the_style.top) + 100;
if (document.layers)
{
the_style.left = the_left;
the_style.top = the_top;
}
else
{
the_style.left = the_left + "px";
the_style.top = the_top + "px";
}
}

function getStyleObject(objectId) {
// cross-browser function to get an object's style
object given its
if(document.getElementById &&
document.getElementById(objectId)) {
// W3C DOM
return document.getElementById(objectId).style;
} else if (document.all && document.all(objectId)) {
// MSIE 4 DOM
return document.all(objectId).style;
} else if (document.layers && document.layers[objectId]) {
// NN 4 DOM.. note: this won't find nested layers
return document.layers[objectId];
} else {
return false;
}
} // getStyleObject

// -->
</script>
</head>
<body>
<a href="#" onClick="moveDiv(); return false;">move the div</a>

<div id="myDiv"
style="position:absolute;top:50px;left:10px;"><img
src='move.gif'/>
</div>

</body>
</html>

Is This Answer Correct ?    2 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of Void(0)?

803


What are the different types of errors in javascript?

693


What is the use of history object?

858


Is javascript frontend or backend?

633


What is escape & unescape String functions in JavaScript?

744


Explain hoisting in javascript?

822


What is the difference between a web-garden and a web-farm?

685


What is Date object in JavaScript?

746


How do I write script-generated content to another window?

692


Are namespaces are there in javascript?

707


Some XYZ company is arranging for online aptitude tests. Draw detailed E-R diagram for the same..

1840


How to define a anonymous function?

718


Is javascript enabled on chrome?

650


What is the result of below given line of code in java script? 5+4+'7'?

684


What is console.log() and why it is used?

792